If the container is flex and item2 has overlow, the container is rendered to the desired size and the overflow bar is visible.
.Flex_container {
width: 300px;
height: 100px;
display: flex;
flex-direction: column;
}
.item1 {
color: white;
background-color: black;
}
.item2 {
color: white;
background-color: brown;
overflow: auto;
}
<div class="Flex_container">
<div class="item1">
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy ei </p>
</div>
<div class="item2">
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accug elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et at.</p>
</div>
</div>
But when I don't apply flexbox, overflow doesn't seem to work. The container seems to adapt more to the content. I want to know why. I'm just about to learn CSS. And I can't get the question out of my head.
.container {
width: 300px;
height: 100px;
}
.item1 {
color: white;
background-color: black;
}
.item2 {
color: white;
background-color: brown;
overflow: auto;
}
<div class="container">
<div class="item1">
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy ei </p>
</div>
<div class="item2">
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accug elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et at.</p>
</div>
</div>
The container has not adapted to the content. It remains at the height you have given it.
But the heights of the children have not been constrained so they get larger to accommodate their content, and as their parent hasn't got overflow-y set as hidden they can be seen.
Here's an illustration where the two children have slightly transparent backgrounds so you can see the background of the parent, and it ends slightly down the second child in this instance.
.container {
width: 300px;
height: 100px;
background: magenta;
}
.item1 {
color: white;
background-color: rgba(0, 0, 0, 0.4);
}
.item2 {
color: white;
background-color: rgba(0, 0, 255, 0.4);
overflow: auto;
}
<div class="container">
<div class="item1">
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy ei </p>
</div>
<div class="item2">
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accug elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna
aliquyam erat, sed diam voluptua. At vero eos et at.</p>
</div>
</div>