I always thought that changing the overflow
property of an element's style would only decide what to do with content outside an element's boundaries, not decide whether children are inside or outside.
I have this code:
#container {
border: 2px solid red;
overflow: hidden;
}
#container .left {
width: 50%;
float: left;
}
#container .right {
width: 50%;
float: right;
}
<div id="container">
<h1>container text</h1>
<div class="left">
<h2>left text</h2>
</div>
<div class="right">
<h2>right text</h2>
</div>
</div>
when I change overflow
from hidden
to visible
, the .left
and .right
child elements appear to be outside of their parent box which is in contrast to when the overflow
property is set to hidden
. Why is the overflow
property behaving in this way?