Sticky element on the left side vanishes while scrolling towards the right

My goal is to design a webpage with five distinct regions, out of which three are meant to be sticky. However, while implementing this feature, I encountered an issue - when the user scrolls to the right beyond the viewport width, the left sticky elements disappear. Since I cannot predict the width of the content in advance, I am looking for a solution to allow these elements to automatically expand based on their content. Is there a way to ensure that the left elements remain visible even when the user scrolls all the way to the right?

The regions I have defined are as follows:

  1. header - This region should disappear when the user scrolls vertically.

  2. upperleft - This region is a small column header that remains sticky to the left and top while scrolling.

  3. upperright - This region should stick only to the top while scrolling vertically. It should be hidden behind upperleft when the user scrolls to the right.

  4. bottomleft - This region should stick to the left side of the screen when the user scrolls to the right and disappear behind upperleft when the user scrolls down.

  5. bottomright - This region should be hidden behind upperleft, upperright, and bottomleft based on the user's scrolling actions.

Below is a sample code snippet illustrating the issue (tested on Firefox 62.0.3):

 <!-- CSS code here--> 
 <!-- HTML code here--> 

Answer №1

If you're experiencing an overflow issue, it could be because your body is a block element with a width that won't exceed the dimension of your screen, causing problems with the left sidebar.

An easy solution is to change the body to inline-grid:

body {
  margin: 1rem;
  display: inline-grid;
  grid-template-columns: 3rem auto;
  grid-template-rows: 12vh 2rem auto;
  grid-template-areas: "header header" "topleft topright" "bottomleft bottomright";
}

/* CSS styles for header, topleft, topright, bottomleft, bottomright */
<div class="header">
This intro area should be visible until scrolled out of view.
</div>
<div class="topleft">
Stay
</div>
<div class="topright">
Top line sticky vertically but not horizontally
</div>
<div class="bottomleft">
Large vertical data set
</div>
<div class="bottomright">
Large area with cells
</div>

To visualize the issue better, add a border to the initial code, and you'll see the left sidebar stop at that border:

body {
  margin: 1rem;
  display: grid;
  border: 2px solid red;
  grid-template-columns: 3rem auto;
  grid-template-rows: 12vh 2rem auto;
  grid-template-areas: "header header" "topleft topright" "bottomleft bottomright";
}

/* CSS styles for header, topleft, topright, bottomleft, bottomright */
<div class="header">
This intro area should be visible until scrolled out of view.
</div>
<div class="topleft">
Stay
</div>
<div class="topright">
Top line sticky vertically but not horizontally
</div>
<div class="bottomleft">
Large vertical data set
</div>
<div class="bottomright">
Large area with cells
</div>

As a tip, it's best to avoid using the body as a container and instead create your own container for easier structure and integration:

body {
  margin: 0;
}

.container {
  margin: 1rem;
  display: inline-grid;
  border: 2px solid red;
  grid-template-columns: 3rem auto;
  grid-template-rows: 12vh 2rem auto;
  grid-template-areas: "header header" "topleft topright" "bottomleft bottomright";
}

/* CSS styles for header, topleft, topright, bottomleft, bottomright */
<div class="container">
  <div class="header">
    This intro area should be visible until scrolled out of view.
  </div>
  <div class="topleft">
    Stay
  </div>
  <div class="topright">
    Top line sticky vertically but not horizontally
  </div>
  <div class="bottomleft">
    Large vertical data set
  </div>
  <div class="bottomright">
    Large area with cells
  </div>
</div>

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

What is the best way to design a form with two dropdown menus, where the options in the second dropdown menu are determined by the selection made in the first dropdown menu

Is it possible to create two select menus using one dictionary in Django, where the values in the second menu are dependent on the key selected in the first menu? In my Django views.py file, I've constructed a dictionary with Projects as keys and cor ...

Using jQuery AJAX to Transfer Data to a PHP Script

There is a div element with a data-id attribute. The goal is to use jQuery to detect when this div is clicked and then send or store the corresponding data-id value in a PHP file. However, the code provided raises an error when trying to obtain the data-id ...

Implementing a watcher property in JavaScript to dynamically add a class to an element

I'm currently facing an issue where I need to apply a class to an element when a certain data property changes. My approach involves using a watcher to monitor the value change and adding a class through JavaScript, as demonstrated in the code snippet ...

My initial junior UI/UX assignment: Can you confirm whether this form modal dialog is pixel-perfect, and offer any suggestions for improvements

Currently diving into my first project as a Junior UX/UI Designer. Coming from a background in software engineering, I decided to challenge myself by focusing on design. I'm seeking feedback on the pixel perfection of this modal window, which my seni ...

Unable to display divs in a stacked format using Bootstrap 5

I need help aligning div's vertically on the page. Currently, all my elements are displaying next to each other instead of stacking one below the other. body { height: 100vh; } <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi ...

Optimizing the rendering of Font-awesome CDN JS for better performance on Pagespeed Insights

Instead of directly linking to the Font Awesome CSS, I have chosen to leverage the JavaScript provided by the trustworthy and efficient Font Awesome CDN. This allows for asynchronous loading of icons on my homepage, ensuring a seamless user experience. How ...

What is the method to adjust the font size for section, subsection, and other sections in Doxygen?

I am looking to customize the font size of \section and \subsection in doxygen's html output. Additionally, I want to include numbering for the sections and sub(sub)sections in the format: 1 Section1 1.1 Subsection1.1 1.1.1 Subsubsection ...

Ensuring proper input with JavaScript form validation

Currently, I am working on implementing a basic form validation feature, but it is not functioning as intended. The desired behavior is for the field border to change color to green or red based on its validity, while displaying text indicating whether t ...

Bx slider - displaying partially hidden slides at the far right while utilizing a full-width carousel

Implementing a slider on my nodejs website using bx slider has been quite an experience. Below is how I achieved it: $(document).ready(function(){ $(".bxslider").bxSlider({ minSlides: 1, maxSlides: 40, slideWidth: 300, ...

Issue with anchor tag not functioning properly within toggle div

Can you please help me troubleshoot why the anchor tag is not functioning properly within my div elements? When I click on the first div, the second div is displayed but the anchor tag inside the first div does not seem to be working. <script> $(&ap ...

Connecting Angular TextArea functionality to the Ctrl-Enter keyboard shortcut

Recently, I've been working on creating a custom functionality for the <textarea> element. My goal is to have the enter key trigger a specific function, while using ctrl+enter will add a new line in the textarea. I've tried looking through ...

Code not functioning properly in Internet Explorer

In one of my JavaScript functions, I have the following CSS line which works well in all browsers except for IE (Internet Explorer). When the page loads, the height of the element is only about 4px. element.setAttribute('style', "height: 15px;") ...

What could be the reason for the CSS stylesheet not functioning properly on mobile devices?

I am a newcomer to web development and currently working on a website for a massage therapist using bootstrap. However, I am facing an issue where my CSS styles are not displaying correctly on mobile devices. The backgrounds and bootstrap navbar disappear, ...

Error: Unexpected end of argument list in file c:/.../list.ejs during ejs compilation

Hello, I am a beginner in programming and I have been working hard to learn. Unfortunately, I encountered a SyntaxError: missing) after argument list in c://.../list.ejs while compiling ejs error and I am struggling to find the solution. I am reaching out ...

Gather information from "div" tag with the class attribute using Python

I am looking to extract specific financial data (referred to as the Key data) that is housed within <div> </div> tags. I then aim to consolidate this extracted information into an excel sheet which already contains additional harvested data. Th ...

The Cordova advanced HTTP POST request functionality is not functioning as expected

I'm currently in the process of connecting my backend to a cordova application, and at this early stage of development, I'm attempting to test it in the browser. Unfortunately, I'm facing an issue with the post request not working, as well a ...

The Animation effect of jQuery Making an Element Move Down

After playing around with a jsFiddle, I'm faced with a dilemma. When I try to animate a "drawer" using jQuery, my text mysteriously jumps down a few pixels during the slide animation. It's puzzling me and I'm struggling to pinpoint the cause ...

Load the iframe element only when the specified class becomes visible within the container div, without relying on jQuery

I am facing a unique challenge where the performance of my page is significantly impacted by loading multiple iframes. These iframes are contained within popup modals, and I would like to delay their loading until a user clicks on the modal. When the mod ...

Adjust the cell text overflow based on the width of the table

I am working with a table that has multiple columns. I want the first 3 columns to have a larger width than the others, specifically taking up 15% each for a total of 45% of the table's width. Currently, I am using this code in a sandbox environment: ...

Searching dynamically using class names with JQuery

I am seeking to create a dynamic search input based on the class names within the span tags. However, I am struggling with displaying the class name that I have identified. My goal is to show the class names that match the entered value in the input on the ...