Horizontal scrolling overflow disrupts vertical overflow visibility

I am attempting to display a container containing input elements that receive a warning bubble positioned absolutely when the input is invalid. However, the issue I am facing is that the bubble does not extend beyond the boundaries of the container as anticipated.

The problem can be replicated by nesting div elements three levels deep. Here is the HTML code:

<div id="a">
  <div id="b">
    USER INPUT
    <div id="c">BUBBLE</div>
  </div>
</div>

And here is the CSS code:

#a {
  background-color: #EEEEEE;
  padding: 10px;
  overflow-x: auto;
  overflow-y: visible;
}

#b {
  background-color: pink;
  position: relative;
}

#c {
  background-color: springgreen;
  position: absolute;
  top: 100%;
  left: 0;
}

I have combined them in a Codepen.

The intermediate layer (the input) has relative positioning, while the innermost layer (the bubble) is absolutely positioned directly below it. My intention is for the outermost div to scroll horizontally if there is horizontal overflow, but for the vertical overflow to be visible outside the container. As a result, I have defined overflow-x: auto and overflow-y: visible on this outermost layer. However, instead of the bubble extending beyond the container vertically, I get vertical scrolling.

If I change overflow-x to visible, the vertical scrolling disappears, which is puzzling to me. Why does changing the horizontal overflow setting impact how vertical overflow is handled? Is there a way to achieve horizontal scrolling for overflow while keeping vertical overflow visible?

Answer №1

Regrettably, achieving this is not as simple as adjusting overflow properties. To understand the peculiar behavior of overflow properties, check out this detailed answer:

In essence, even if you specify overflow-y as visible, it will default to auto if overflow-x is set to anything other than visible.

This response suggests a potential workaround that might suit your needs: "overflow-y: scroll;" is hiding overflowing elements on the horizontal line

#parent {
  display: inline-block;
  position: relative;
}

#absolute-child {
  position: absolute;
  bottom: -15px;
}

#child {
  overflow-x: scroll;
  width: 200px;
}

.child {
  width: 400px;
  background: linear-gradient(to right, white, lightblue);
}
<div id="parent">
  <div id="absolute-child">
    overflow
  </div>
  <div id="child">
    <div class="child">child</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

Enhance your table layout with Bootstrap 3 by adjusting textarea size to fill

I am currently in the process of developing a forum and bulletin board software. I am facing some challenges while trying to integrate a reply section into the thread page. You can view what I have implemented so far here. Html: <div class="panel pane ...

Discovering the screen width and increasing its value using CSS

Is there a way to determine the screen size and then add 253px to it? For example, in CSS: .element { width: calc(100% + 253px); } What would be the best approach to achieve this? ...

Can display-inline-block support top margin and text alignment?

Can you please explain if the top margin and text-align properties work for both display: inline and display:inline-block? If they do, could you provide some insight as to why? ...

Having a Jquery resizing problem? No worries! When the width is less than 768, simply enable the click option. And when the width is

HTML <div class="profile"> <a href="#" class="hoverdropdown" onclick="return false;">Profile</a> <ul class="dropdown" style="display: none;"> <li><a href="#">Dashboard&l ...

Issues with CSS compatibility have been identified on Internet Explorer version 7

Currently, I am in the process of working on a website. You can access it through this link. The good news is that the site functions well on FireFox, Chrome, and IE 8. However, the bad news is that it does not display properly on IE 7. There are alignme ...

Issues with jQuery Slider not functioning properly within asp.net webform

I have implemented an Awkward slider to display images for my article. I made some CSS modifications to change the design and it worked perfectly fine when used on an HTML page. However, when I tried using it with an ASP.NET web form, it failed to work fo ...

Can the floating side of a div be switched after resizing?

Let's say I have two divs set up in the following configuration: |------------------------------| | div1 ------------------ div2 | |------------------------------| .div1{ float:left; } .div2{ float:right; } From my understanding, they w ...

Flexible layout of perfectly square elements

I am currently working on creating a responsive grid layout consisting of squares that are positioned absolutely within their parent element. The goal is to ensure that when the page is resized, the squares scale proportionally with their parent container ...

The pseudo class before is experiencing issues with background color in Safari and not functioning as

Issue with Pseudo class before not displaying background colour in Safari browser To view the code, please visit the following link here HTML <div id='test'> <p>Test </p> </div> CSS #test { position: relative; per ...

When attempting to change an image using JavaScript, the image fails to load

I am having trouble understanding what is wrong with my code. <html> <body> <script type="text/javascript"> function changeImage() { var image = document.getElementById('myImage'); if (image.src.match("bulbon")) { ...

How can I create two buttons on one line in a Struts2 form?

My form has two buttons - one for registering and the other for canceling the form. I created them using the following code: <s:submit name="cancel" key="project.button.cancel" /> <s:submit name="login" key="form.register.registerBtn" /> How ...

Fixed Sidebar Position Changes when Bootstrap Modal Closes

We are facing a peculiar issue in our React application involving a sidebar and a bootstrap modal. The problem arises when we click the "X" button in the modal, causing the sidebar to momentarily drop down the page before the modal closes. This strange be ...

Tips on modifying the background color of a read-only field in an edit form

Changing the background color of a readonly field in the edit form of Free jqgrid can be a challenge. One potential solution involves specifying a style: .jqgrid-readonlycolumn { background-color: #FFFFDD; } This style is then used in the colmodel e ...

Positioning the filters in jQuery Datatables

I'm currently working with jQuery datatables and I'm attempting to align the filter/search box on the same row as the header of the container holding the datatable. Attached is a screenshot for reference: https://i.stack.imgur.com/nzbIl.png He ...

How can custom selectors be created in LESS?

Let me provide an example of my desired approach. :all() { &, &:link, &:visited, &:active, &:focus } The concept above involves a 'custom selector' that encompasses all pseudo-classes of an anchor tag, e ...

Animations with absolute positioning not rendering correctly in Safari

I recently created a basic animation that involves setting an element to "position: absolute" in order to translate it. Everything functions perfectly as intended on Chrome, however, when testing it on Safari, the absolute positioning seems to be completel ...

adjusting the color of ion-button when hovering over the cancel button

I'm working on a button bar for my app and I want the color of the button to change based on its state (false, true). Currently, the button starts out green, turns light green when hovered over, and becomes white when clicked. Once I click it, the bu ...

The vertical-align property fails to properly align the list-style-image with the text

My HTML list is structured like this: <ul id="remove"> <li id="rm_txt_1" onClick="remove_1();">Remove </li> </ul> <ul id="move"> <li id="mv_txt_1" onClick="position();">Move Down</li> </ul> It is styled u ...

Step-by-step guide on aligning a div of unknown height in the center of a div with a set

Struggling to center product images vertically within a fixed height box? Here's the code I've been working with: <div class="main-pic"> <ul> <li><img src="images/extra/laptop.jpg"></li> <li><img ...

Overflow-y SweetAlert Icon

Struggling with a website modification issue where using Swal.fire(...) causes an overflow problem affecting the icon rendering. How can this be fixed? Here is the custom CSS code in question: * { margin: 0px; padding: 0px; font-family: &ap ...