Aligning two columns accurately

Utilizing Jquery, I have implemented the .offset() method to precisely position two columns that span 100% of the page height, serving as drop shadows for the content margins.

The CSS styling applied to these columns is:

div#lshade,
div#rshade
{
    width: 60px;
    display: block;
    position: fixed;
    height: 100%;
}

div#lshade
{
    background: url(/_private/display/layout/lshade.png) repeat-y;
}

div#rshade
{
    background: url(/_private/display/layout/rshade.png) repeat-y;
}

Below is the JQuery code in use:

function loaded()
{
    setInterval("fixShade()", 33);
}

function fixShade()
{
    var left = $("#lshade");
    var right = $("#rshade");

    var cont = $("#content").offset();

    left.offset({top: 0, left: cont.left});
    right.offset({top: 0, left: cont.left + 900});
}

Initially, everything functioned seamlessly until the page content length necessitated scrolling. Post-scroll, the columns erroneously ascended with the page despite being set as fixed.

This behavior suggests that using offset() may override the fixed property.

The intended outcome is constant alignment at the top of the page and spanning the full height (akin to position: fixed;).

A potential solution involves setting horizontal positioning accurately while ensuring vertical attachment to the scrolled window position (the top).

To view the current embodiment of my project, please visit:

Answer №1

It appears that the offset is only capturing the height of your left or right shading element. You can try:

left.offset({top: 0, left: cont.left}).css("height",$(window).height());

or

left.offset({top: 0, left: cont.left}).css("height",$(document).height());

Alternatively, your best option might be:

left.offset({top: 0, left: cont.left}).css("height",$("#innerContent").height());

If not, you may need to determine the height of another element that extends all the way down. Perhaps it could be innerContent.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with Bootstrap Navbar-Toggle Functionality in ASP.NET with Visual Studio 2010 Not Resolving

After installing a NuGet package, I proceeded to install Bootstrap which created the following folders: Contents containing Bootstrap CSS files Scripts containing .js files In the header of my Master Page, I included the scripts like this: <scrip ...

Maintaining text in a straight line

My design includes an image floated to the left with text aligned to the right of the image. Unfortunately, the text is too long, causing a line from a paragraph to drop below the image. How can I ensure that the text stays in line with the paragraph and ...

Is there a way for me to access the response from the PHP file I'm calling with Ajax?

I am just starting to explore ajax and jquery, and I recently found a code online that I'm tweaking for my own use. However, I am struggling with how to handle responses from PHP in this context. The current setup involves ajax POSTing to a php page ...

Tips for managing and accessing my personal app page history

I developed a single-page application that loads content using jQuery ajax calls. To enhance user experience, I implemented a basic back button feature that overrides the default back functionality on mobile devices. My current method involves storing pa ...

Choosing a unique font style in CSS (OTF) - How to differentiate between bold, italic, etc. when using multiple OTF files?

I'm a little confused on how to implement @font-face in my current project. The client handed over multiple font files including FontName-Black.otf, FontName-BlackItalic.otf, FontName-Bold.otf, FontName-BoldItalic.otf, and more. My usual approach wou ...

Arranging two input boxes side by side: a step-by-step guide

I designed two input boxes and tried to move them together, but unfortunately my code is not working as expected It seems like a simple issue, yet the input boxes are displaying like a list rather than side by side. <link href="https://cdnjs.cloud ...

ignore any anchors beyond the second index

I am working with a django-qcm that has dynamic sections triggered by anchors and utilizes the scroll snap type property. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv ...

Using Jquery's closest technique to target a class located outside of the parent div

I am having trouble accessing a class outside of its parent div $(document).on('click', '.delete_photo', function(event){ var del_id = $(this).attr('id'); $.ajax({ type:'POST', cache: false, url:&apo ...

What is the best way to ensure a bottom tooltip stays perfectly aligned with the right edge of its corresponding element?

Currently, I am trying to implement a tooltip above my progress bar. However, the small tooltip that I have is not functioning correctly... This is how it currently appears: https://i.sstatic.net/ZJUyT.png I need the tooltip to display above the white d ...

Triggering the retrieval of complete HTML content by clicking a button in order to load extra elements using Selenium

My goal is to scrape a webpage and gather all the links present on it. The page displays 30 entries and to access the complete list, one must click on a "load all" button. Below is the Python code snippet I'm currently using for this task: from sele ...

Is there a way to grab code from a different HTML page using JavaScript and jQuery when the user clicks on something?

After testing various codes for the intended purpose mentioned in the title, I have observed a peculiar behavior. The code from settings.html appears briefly and then disappears rapidly. Javascript: function load() { $("#paste").load("settings.html") ...

Activate tooltip when hovering over the <img> element

I am having trouble implementing a tooltip using CSS for an <img> element. While I have successfully added a tooltip to <a href> </a> tags, applying the same functionality to an <img> tag has proven difficult. http://jsfiddle.net/ ...

Reduce opacity of div upon clicking javascript:history.back()

I have successfully implemented a fadeIn CSS animation, but I am facing an issue where the block disappears abruptly when I click the close button. Is there a way to reverse the animation when the user clicks the "close" link (which triggers javascript:his ...

Utilizing CSS and JQUERY for Styling Border radius

Is there a way in jQuery to select specific parts and apply a "border radius"? I've been struggling to use a jQuery selector to achieve this. Is there another method using CSS? I don't want to manually add a "CLASS" to the HTML code to solve th ...

Develop fresh JavaScript code using JavaScript

Is it possible to dynamically create a new row in an HTML table by clicking on a button? Each row contains multiple input fields. <script type="text/javascript> row = 2; specific_row_id = new Array(); $(document).ready(function() { $(".change_1 ...

In the mobile view of the jumbotron, there is a noticeable blank area on the right side

I've searched high and low for a solution to this issue, but nothing seems to pinpoint the cause of the problem. The white space that's causing trouble is evident in the following image: https://i.sstatic.net/95Rh6.jpg Could you help me identif ...

Updating user credits through the Model::factory() method is a common practice in my workflow

I need to update the UserCredits after a purchase. For example, if a user currently has 10 credits and purchases 10 more, I want to add the purchased credits to their existing total. The goal is to increment the current credit score with the new credits ...

Comparison between global and local styling in VueJS

As I develop a project using .vue files, I find it beneficial to have the ability to write CSS (SASS), JS, and HTML all within the same file. For my global components written in SASS, I have created an assets/styles/app.scss file to house my grid, variabl ...

Using Php and MySQL to extract information from a database depending on the hyperlink selected by a user

I have incorporated a series of small images on a webpage to act as links, around 50 in total. On the same page, there is a content placeholder that fetches data from a database. I have a table stored in phpmyadmin with fields filled with relevant informat ...

The issue of background size failing to update even after CSS file has been modified

I am in the process of creating a web UI that currently features a blue banner. I have attempted to adjust its size in the CSS code below, but unfortunately, the changes do not seem to take effect. Previously, the background-size property was set to cover, ...