HTML:
<div id="container">
<div class="item">Foo</div>
<div class="item">Bar</div>
</div>
CSS:
#container {
display: flex;
justify-content: center;
overflow: auto;
}
.item {
flex-grow: 1;
min-width: 200px;
max-width: 300px;
}
As the container shrinks to less than 400px, a horizontal scroll bar appears as expected. However, the first item starts getting hidden by the left edge of the container, even when completely scrolled to the left. The more the container shrinks, the more the item gets obscured.
See the live demonstration here: http://jsfiddle.net/FTKcQ/. Resize the result frame to see the issue. This has been tested in Chrome 30 and Firefox 24 browsers.
If the value of justify-content
is changed from center
to any other value (e.g. space-between
), all content becomes visible upon scrolling. Why does this difference occur with centered items?
The aim here is to have a row of centered items that expand within a certain range. If the minimum-width items cannot fit in the container, it should be able to scroll to show all items.