I have found that a flexbox container does not scroll through all child elements properly with overflow: auto
and justify-content: center
. With fewer elements, everything works well (elements are centered in the container). When the content overflows, however, elements to the left are cut off inside the scrolling div.
I have found that setting justify-content: space-between
does not cut anything off, but that is not the intended behavior. I also know this can be done sans flexbox, but does anyone know why this is not working?
JSFiddle examples:
Few elements, works fine: https://jsfiddle.net/z50g5ysu/2/
Overflowing elements, those to left get cut off: https://jsfiddle.net/z50g5ysu/3/
HTML:
<div class="flex-container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
CSS:
.flex-container {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
height: 150px;
width: 400px;
border: 2px solid red;
overflow-x: auto;
}
.box {
height: 100px;
width: 100px;
border: 2px solid black;
margin: 10px;
flex: none;
}