Additional Flexbox and Sticky Positioning

Adding Another Dilemma to the Position Sticky and Display Flex Mix

I'm facing a new challenge with a webpage layout that involves nested flex containers. The layout consists of an outermost container with a row direction, containing two nested columns with a column direction.

The left column contains text, while the right column has two nested flex containers with images or text, positioned at the top and bottom using justify-content: space-around.

My goal is to make the top container in the right column sticky within its parent container, with a 50px offset from the top.

Due to more content in the left column than the right one, there's extra white space between the top and bottom containers in the right column when using justify-content: space-around. I believe making the top container sticky will allow it to move through this space as users scroll down the text on the left.

To better illustrate the layout, here's a rough sketch:

https://i.sstatic.net/I9PKH.png

For the CSS associated with each flex box, here's what I currently have:

1. Outermost Flex Container (Row):

flex-direction: row;
flex-wrap: wrap;
justify-content: space-around;
height: 100%;
overflow: visible;

2a. First / Left Nested Flex Container (Column)

flex-direction: column;
justify-content: center;
align-items: center;
max-width: 60ch;
padding: 25px;
background: var(--gray_card);
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);

2b. Second / Right Nested Flex Container (Column)

flex-direction: column;
justify-content: space-between;
padding: 25px;

3a. First / Top Flex Container

position: -webkit-sticky;
position: sticky;
top: 50px
flex-direction: column;
align-self: center;
justify-content: space-evenly;
margin: 10px 0px;
border: 1px solid lightgray;
border-radius: var(--border_radius);
background: var(--white);

3b. Second / Bottom Flex Container

flex-direction: column;
justify-content: center;
align-content: center;
align-self: center;
border-radius: var(--border_radius);
padding: 35px;
background: var(--gray_card);

4. Flex Container (Row)

align-self: center;
justify-content: space-evenly;
margin: 10px 0px;
border: 1px solid lightgray;
border-radius: var(--border_radius);
background: var(--white);

Despite my efforts and various attempts, including adjusting overflow properties, the position: sticky doesn't seem to work on Flex Container 3a. There might be a flexbox logic issue causing this, but I haven't been able to find a solution yet. Any insights would be greatly appreciated!

Thank you for your assistance!

Answer №1

UPDATE: Uncovered the issue.

After some investigation, I discovered that the main element on this specific page was actually set to overflow: hidden...but in a separate Sass file located lower down in the head section of the page. This conflicting Sass file was overriding the changes I had made to the main element higher up in the head.

To resolve this issue, I assigned an #id to the main element and used that #id to change the style to overflow: visible in my custom stylesheet designed for this particular page.

This mistake may have been a beginner error, but I am sharing it openly in the hope that it serves as a reminder to fellow developers to always double-check the sequence in which their CSS is loading in the browser.

If, like me, you find yourself including your base styles & resets after the page-specific CSS, it's worth searching for instances of overflow: hidden in those files if you are encountering issues with display: flex and position: sticky not behaving correctly together.

If this approach doesn't yield results, it might be time to explore alternative solutions suggested in other resources such as this post on Stack Overflow.

In my case, the solution turned out to be a simple oversight on my part. However, the interaction between display: flex and position: sticky remains a common challenge that all developers will likely face at some point in their coding journey.

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

color settings on a search icon as a background

I'm struggling to make the background color of my search glyph fill the entire box. I want it to resemble this image. However, at the moment, it looks more like this. I can't figure out what's causing the issue. Below is the HTML code I&a ...

What is the best way to ensure that my top menu remains fixed while scrolling?

Link to website: I am looking to have the top menu on my page remain fixed at the top of the screen as users scroll. Does anyone know if this is achievable, and if so, how can I implement it? ...

Align a span vertically within a div

I need help aligning the content "ABC Company" vertically within a div using Bootstrap 4's alignment helper classes. Despite my efforts, I have not been successful. Here is the code I am using: <div class="container" style="width: 740px;"> < ...

How can you utilize CSS to automatically generate section numbers, specifically for multiple sections?

Is it possible to automatically generate section numbering in CSS only when there are multiple sections present? I discovered that using CSS, one can create automatic numbering for sections. body { counter-reset: section } h2 { counter-reset: sub-section ...

How can you determine the location of a point on the perimeter of a regular polygon?

Imagine you have a pentagon, with numbered sides like moving around a clock: https://i.sstatic.net/pWqdFtfg.png Starting from the center of the polygon, how can you calculate the position of a point in these locations (along the edge of the polygon): At ...

What is the best way to align the subsequent sub-elements to the right edge of the initial child element in a left alignment

Here is the HTML snippet I am working with: .entry{ border: 1px solid gray; } .list_number{ color: red; border: 1px dashed gray; margin-right: 5px; } .entry_body{ border: 1px solid green; } <div class="entry"> <span class=" ...

Maintain the color of a Bootstrap 4 dropdown link even when it is open by incorporating hover

Currently, I am utilizing bootstrap 4 to create a menu that includes dropdown items. The issue I am facing is that when hovering over a dropdown link, the background color changes and the dropdown opens. However, as soon as I move the mouse to select one o ...

Sideways movement of a single line within a table

Would you please help with a challenge I'm facing? I want to create a horizontally scrollable row that spans 100% of the page width without overflowing on top of the background image and while keeping the header text in focus. This is what I have att ...

Having trouble retrieving data from the database using php and ajax

I am currently working with bootstrap, php, and ajax. I'm facing some issues that I can't seem to resolve. Additionally, I've noticed that the mysqli_connect function is not highlighting in blue when I type it in Notepad++. Is this normal? ...

What is causing React Js to fail loading css when switching from anchor tag to link tag?

I am learning React and experimenting with creating a basic static website using HTML templates in version ^18.2.0 of React JS. Everything seems to be functioning correctly, however, I have encountered an issue with page refresh. Specifically, when I repla ...

Strange floating error in Internet Explorer 7

Working on a webpage at this link, I have structured my HTML as follows: <div id="wrapper"> <div id="main"> <div class="images"> <p>Content</p> <div class="clear"></div> ...

What is the best way to address background-image overflow on a webpage?

I'm facing a challenge in removing the overflow from a background-image within a div. There are 4 divs with similar images that combine to form one background image (I adjust the position of each image so they align across the 4 divs). Essentially, I ...

What is the reasoning behind singling out this one line in the bootstrap css?

Incorporated within the starter template for Bootstrap CSS is the following inline snippet: body { padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */ } What are some practical considerations for including t ...

Changing the Appearance of the RStudio Editor

I am exploring options to customize an RStudio Editor Theme to personalize the colors. My current setup includes RStudio version 0.99.473 on Windows 10. After reviewing Any way to change colors in Rstudio to something other than default options?, which wa ...

Place two divs within a parent div that can adjust its width dynamically

Within this lengthy div, there are 4 elements arranged as follows: icon (fixed width) item_name [needs to be accommodated] item_type [needs to be accommodated] item_date (fixed width) I am currently attempting to find a way to ensure that the it ...

Tips for modifying CSS based on the user's Operating System

Is there a way to write CSS that produces different effects on Mac OS compared to other operating systems? For example: .(mac){ height: 100%; width: 100%; overflow: hidden; } .(win and linux){ height: 100%; width: 100%; ...

Enhance the menu by incorporating an elegant arch design between each item

I am trying to create a menu layout like the one shown in this screenshot. I have been struggling to find an efficient way to style it on my own. Can anyone provide some suggestions or assistance? View expected menu design I am having trouble figuring ou ...

Tips for returning an element to its starting position following animation

Hey there, I’m fairly new to the world of HTML and CSS. Recently, I was working on creating a YouTube clone website and I’ve run into an issue with the navigation. On the official YouTube website, when you click on the hamburger menu icon, the naviga ...

Adjust the dimensions of the thead, tbody, and td elements on the fly

I've implemented this property in a .css file on the table shown below and there are 9 records. .fixed tbody td, thead th { width: 5.2%; float: left; } In my scenario, when there are 4 columns, the width should be 23.2%; for 5 columns ...

Achieving a compressed display of an HTML table

My boss recently asked me to enhance the responsiveness of a table on our website. I initially followed the solution discussed in my previous query about making tables responsive (Responsive Table Display) However, after completing that implementation, I ...