The flexible box model makes it incredibly easy for vertical alignment. The problem that I constantly encounter is that when you resize the viewport to "too small" size, the inner box will overflow at the top, despite the element located in the overflow: auto element. In other words, you can scroll to the bottom (as expected using overflow: auto ), but that doesn't work the other way around.
#con { width: 300px; height: 100px; background: yellow; display: flex; align-items: center; justify-content: center; overflow: auto; } #center { background: green; color: white; }
<div id="con"> <div id="center"> Invisible<br/> 2<br/> 3<br/> 4<br/> 5<br/> 6<br/> 7<br/> 8<br/> 9<br/> 10 </div> </div>
Now I understand why this happens in different ways, but I have no idea how best to solve it. How can you align something in the center with a flexible box model, but let the element overflow if it doesn't fit ?
source share