Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get position:absolute child to overflow the parent dimensions when parent overflow is auto?

Tags:

html

css

#container {
  width: 200px;
  height: 200px;
  background:red;
  overflow: auto;
  position: relative;
}

#absolute {
  position: absolute;
  top: 50px;
  left: 0;
  width: 400px;
  height: 20px;
  background: yellow;
}
<header>Header</header>
<div id="container">
  <div id="absolute"></div>
</div>
<footer>Footer</footer>

I have an absolute positioned yellow bar here that is wider than the parent box. I'd like the full bar to be visible and not be clipped by the parent dimensions. Is it possible to do that using some combination of CSS properties?

I'm aware that removing overflow:auto from the parent gives the effect I am asking for but removing that is not an option, unfortunately.

like image 435
Coffee Bite Avatar asked Jan 30 '26 14:01

Coffee Bite


1 Answers

I added another wrapper that has the overflow: auto; and removed it from the main container

#container {
  width: 200px;
  height: 200px;
  background: red;
  position: relative;
}

.subcon {
  overflow: auto;
}

#absolute {
  position: absolute;
  top: 50px;
  left: 0;
  width: 400px;
  height: 20px;
  background: yellow;
}
<header>Header</header>
<div id="container">
  <div class="subcon">
    <div id="absolute"></div>
  </div>
</div>
<footer>Footer</footer>
like image 189
Carl Binalla Avatar answered Feb 02 '26 09:02

Carl Binalla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!