I want to use flexbox to position div children inside a div container.
I want them centered inside the container so I use justify-content: center; and align-items: center;. I also want the children to wrap if there are too many to display side by side, so I use flex-wrap: wrap; and align-content: center;. Everything works as expected as long as all content can be fit inside the container.
If the window is really small however the content is overflowing the container and it does show scrollbars, but the first child is still outside the scroll area. This does not happen when align-content is anything other than center.
It happens in safari, chrome and firefox so I assume it is not a bug.
Any idea what causes this and how to fix it?
I also made a codepen to illustrate this (make the browser window as small as possible and scroll to the top to see the first child clipped from view): http://codepen.io/SubHero/pen/bpZXzm
HTML:
<div class="parent">
<div class="child">Child1</div>
<div class="child">Child2</div>
<div class="child">Child3</div>
<div class="child">Child4</div>
</div>
CSS:
* {
margin: 0;
padding: 0;
}
html, body {
width: 100%;
height: 100%;
}
body {
display: flex;
}
.parent {
display: flex;
flex-grow: 1;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-items: center;
align-content: center;
}
.child {
width: 300px;
height: 200px;
margin: 20px;
background-color: #4caf50;
}