Can parents with 'overflow: hidden' be overridden using 'position: sticky'?

I am dealing with a specific layout challenge involving two columns, where I need the right column to remain fixed in place while scrolling through the longer left column.

These columns are built using Bootstrap, so initially, I had to eliminate floats and utilize display: inline-block. This approach functions properly when implemented at the top of the page's DOM structure. However, as it is rendered further down, approximately 30 divs deep, the sticky positioning fails to work as desired.

I understand that an overflow property set on a parent element can interfere with position: sticky, but this does not seem to be the root cause in this scenario. Could the issue be related to any ancestor elements having overflow properties set that disrupt sticky positioning?

In such situations, I am uncertain about what factors to investigate to identify the problem accurately. Are there any specific considerations to keep in mind when working with sticky positioning?

EDIT: Upon closer investigation and testing, it appears that an ancestral element near the top of the DOM tree has been assigned overflow-x: hidden. Since this code is shared, I will need to locate the reason for this setting and its necessity.

Meanwhile, is there a workaround available whereby an element further down in the DOM hierarchy can function as the containing element for maintaining sticky positioning?

In the demo below, eliminating overflow from .theproblem restores the desired behavior (the right column sticks during page scroll).

.theproblem {
    overflow-x: hidden;
}

.column {
    display: inline-block;
    width: 45%;
    vertical-align: top;
}

.column1 {
    border: 1px solid red;
    height: 1000px;
}

.column2 {
    border: 1px solid green;
    position: sticky;
    top: 1px;
}
<div class="theproblem">
  <div class="columnwrapper">
    <div class="column column1">
      This is column 1 (the tall one)
    </div>
    <div class="column column2">
      This is column 2 (the sticky one)
    </div>
  </div>
</div>

JSBin link

Answer №1

It has been observed that any overflow property between the sticky position and scrolling can cause it to break (referenced here: Why is 'position: sticky' not working with Core UI's Bootstrap CSS and here What are `scrolling boxes`?).

In your situation, one solution is to transfer the scroll functionality to a different element while hiding the default one:

.theproblem {
  overflow-x: hidden;
}
/* Added this */
.columnwrapper {
  height:100vh;
  overflow:auto;
}
body {
  overflow:hidden;
  margin:0;
}
/**/

.column {
  display: inline-block;
  width: 45%;
  vertical-align: top;
}

.column1 {
  border: 1px solid red;
  height: 1000px;
}

.column2 {
  border: 1px solid green;
  position: sticky;
  top: 1px;
}
<div class="theproblem">
  <div class="columnwrapper">
    <div class="column column1>
      This is column 1 (the tall one)
    </div>
    <div class="column column2">
      This is column 2 (the sticky one)
    </div>
  </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

Difficulty encountered when positioning a container using BootStrap 4

As a newcomer to the world of web development, I encountered an issue while trying to align a container on my webpage. Despite my efforts to center the container using (line 30), the page seems to update but there is no visible change. Can anyone help me ...

Enhance your webpage by incorporating a CSS subclass using jQuery's addClass

Attempting to apply a subclass to a class using jQuery has proven tricky. The CSS in question is as follows: .block:nth-child(7) .permahover { top: 0 !important; left: 0 !important; opacity: 0; filter: alpha(opacity=0); -webkit-transform: t ...

Styling JSPDF Auto Table with Class-Specific Customizations

Here's a table I have: <table id="tbl"> <thead> <tr> <th>Name</th> <th>Amount</th> </tr> </thead> <tbody> <tr> <td class="left-align" ...

Simple steps to emphasize a table cell in Angular 2

Essentially, I have a table structured as shown below <table> <tr> <td>Date</td> <td>Time</td> <tr> <table> The goal is to make both the date and time clickable within this table. When clicking on the date, ...

Incorporate gulp-clean-css into the current gulpfile.js

I was recently provided with a gulpfile.js file by a colleague, which contains the code below. It keeps an eye on my scss files and compiles them when I save. var gulp = require('gulp'), gutil = require('gulp-util'), browser ...

Carving out an SVG Mask within an image

I'm encountering an issue with a new website I'm working on. This is my first time utilizing SVG's. Essentially, I need to crop a circle that remains centered on the page from my image to reveal the image beneath the element. Although I atte ...

"Fixing the position of a div on the Samsung Galaxy S8 navigation bar to

Here is the HTML code I am working with: <div class="app-bar"> <a href="#'>icon</a> <a href="#'>icon</a> <a href="#'>icon</a> <a href="#'>icon</a> </div>' ...

Having trouble customizing my navigation bar with the provided classes for navigation bar styling

My current project involves creating an ecommerce site using HTML and CSS. I utilized a navigation bar template from Bootstrap, but I'm encountering difficulty in styling the .navbar-light .navbar-nav .nav-link classes. As a beginner, this is my first ...

overrule styling in react native

In React Native, I am looking to modify a specific style within a sub-component. For instance, I have defined a style called CircleShapeView: const styles = StyleSheet.create({ CircleShapeView: { width: 50, height: 50, borde ...

What is the process for changing text to red when hovering over it in a nested list?

a { color:black; } a:hover { color:red; } <ol> <a href="#"><li>Main1</li></a> <a href="#"><li>Main2</li> <a href="#"><li>Main3 <ol> ...

I am looking to bring in just the tables from a different html/php page

I am currently working on a webpage that includes a php library, header, and other elements. I only need to import specific tables and information from this page onto another screen display, with the tables arranged side by side instead of vertically. My ...

Navigating Through Secondary Navigation with Ease

In my React project, I am developing a mega-menu styled dropdown navigation. As a functional component, I am utilizing the useState hook to manage the state and control the display of sub-navigation items. The functionality of the dropdown is operational, ...

The divider amidst the cards zapping like electricity

Is there a way to create a vertical bar that resembles lightning? Something like this: https://i.sstatic.net/biEGb.png <div class="row d-flex justify-content-center"> <div class="col-md-3"> <div class=" ...

What is the best way to align the navigation menu in the center?

<nav> <a href="/C:\Users\Emily O\Documents\WebDevelopment\JamminJava/index.html">Home</a> | <a href="/C:\Users\Emily O\Documents\WebDevelopment\JamminJava/menu.html">Menu</a> | ...

Hide the paragraph element when the navigation link is being hovered over

Is there a way to hide a <p> element when hovering over a link? My website is built with Drupal and uses the Superfish module for the navigation bar. When I hover over the links, a secondary nav bar drops down. I want the slogan of the website to di ...

What could be causing sporadic disappearance of my background image?

Feeling overwhelmed by this sudden issue on my WordPress site. The logo isn't working properly, and I've saved this page as HTML for reference. Check out the link: Oddly enough, leaving a page open for a while or navigating away and returning t ...

Challenge with CSS selectors

Here is the HTML code I am working with: <label for="tx_alterneteducationcatalog_subscriberadd[newSubscriber][gender]" class="error" id="tx_alterneteducationcatalog_subscriberadd[newSubscriber] [gender]-error">This field is required.</label> ...

In Javascript, swap out a particular colored region in an image with a different image

I've been scouring the internet in search of a solution to my problem, but it seems like I might not be looking in the right places. Imagine this image below, how can I replace the blue area with an image uploaded by the user? I'm struggling to ...

Is there a problem with the drop-down menu not closing on WordPress?

I have successfully implemented a transition effect for the dropdown menu in my custom WordPress theme. However, I am facing an issue where the transition effect does not appear when the cursor moves away from the dropdown menu while closing. To see this i ...

Importing fonts using CSS

Currently, I have 4 different fonts that I need to incorporate into a website, and their files are saved within my website folder. Baskerville.ttc BellGothicstd-Black.otf BellGothicstd-Bold.otf JennaSue.ttf I attempted to import the fonts using @Import, ...