I have a major issue with flexbox layout. I build a container with a boxes filled with images, and i decided to use flexbox layout to justify the content to make it looks like a grid
Her's the code:
<div class="container">
<div class="item"></div>
<div class="item"></div>
...
<div class="item"></div>
</div>
and the CSS:
.container {
display: flex;
display: -webkit-flex;
display: -moz-flex;
justify-content: space-around;
-webkit-justify-content: space-around;
-moz-justify-content: space-around;
flex-flow: row wrap;
-webkit-flex-flow: row wrap;
-moz-flex-flow: row wrap;
}
.container .item { width: 130px; height: 180px; background: red; margin: 0 1% 24px; }
And everything looks good except the last line/row - when it not contain the same number of element that other lines, centering elements and it broke my grid effect.
http://jsfiddle.net/puz219/7Hq2E/
How to align last line/row to left side?
This is not an effect you wanted to achieve?
http://jsfiddle.net/7Hq2E/21/
CSS:
HTML:
You can use flexbox with
max-width
(vendor prefixes removed):And the HTML
View on CodePen: http://codepen.io/anon/pen/gpwEJW
I thought this example might be useful for anyone who wanted multiple items and allow for responsiveness, the grid items change depending on the viewport size. It does not use any invisible children, it's all done through css.
Might help someone trying align items to the left when the last row has less items and they require the page to be responsive.
http://codepen.io/kunji/pen/yNPVVb
Sample HTML
Sample CSS
Unfortunately this is not possible with flexbox.
The best work-around is to add invisible children 'filling up' the empty 'blocks' in the last row. That way, the actual, visible, element is aligned left.
Similar question: Flex-box: Align last row to grid
I've checked it and it worked better in my HTML editor tool
the script should be the way
CSS Part
HTML Part
You can use
margin-right:auto
on the last-child flex item.The problem here is that you will lose the space-between property on the left for this flex item.
Hope it helps!