Position absolute and overflow hidden

HtmlCssLayoutOverflowCss Position

Html Problem Overview


We have two DIVs, one embedded in the other. If the outer DIV is not positioned absolute then the inner DIV, which is positioned absolute, does not obey the overflow hidden of the outer DIV (example).

Is there any chance to make the inner DIV obey the overflow hidden of the outer DIV without setting the outer DIV to position absolute (cause that will muck up our complete layout)? Also position relative for our inner DIV isn't an option as we need to "grow out" of a table TD (exmple).

Are there any other options?

Html Solutions


Solution 1 - Html

Make outer <div> to position: relative and inner <div> to position: absolute. It should work for you.

Solution 2 - Html

What about position: relative for the outer div? In the example that hides the inner one. It also won't move it in its layout since you don't specify a top or left.

Solution 3 - Html

An absolutely positioned element is actually positioned regarding a relative parent, or the nearest found relative parent. So the element with overflow: hidden should be between relative and absolute positioned elements:

<div class="relative-parent">
  <div class="hiding-parent">
    <div class="child"></div>
  </div>
</div>

.relative-parent {
  position:relative;
}
.hiding-parent {
  overflow:hidden;
}
.child {
  position:absolute; 
}

Solution 4 - Html

Make sure.

  1. parent position relative.
  2. parent have manually assigned width and height(important as child element having absolute position).
  3. child position absolute;

.outer{
   position:relative;
   width:200px; 
   height:100px;
   overflow:hidden;
}

.inner{
   position:absolute;
   width:100px;
   height:100px;
   font-size:3rem;
}

<div class="outer">
<div class=inner>
Inner DIV to apply overflw hidden
</div>
</div>

}

Solution 5 - Html

You just make divs like this:

<div style="width:100px; height: 100px; border:1px solid; overflow:hidden; ">
    <br/>
    <div style="position:inherit; width: 200px; height:200px; background:yellow;">
        <br/>
        <div style="position:absolute; width: 500px; height:50px; background:Pink; z-index: 99;">
            <br/>
        </div>
    </div>
</div>

I hope this code will help you :)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionZardozView Question on Stackoverflow
Solution 1 - HtmlshankhanView Answer on Stackoverflow
Solution 2 - HtmlTesserexView Answer on Stackoverflow
Solution 3 - HtmlSi7iusView Answer on Stackoverflow
Solution 4 - HtmlravindraView Answer on Stackoverflow
Solution 5 - HtmlrochanoView Answer on Stackoverflow