I'm trying to get a nice Flexbox grid to use with ecommerce products, but can't quite get it to do what I want.
Here is a demo http://jsbin.com/acejes/9/edit
It may not be possible, I just wanted to check if there's anything else I can do.
Here is my aim…
- Must be a percentage based grid
- The first and last column flush against the sides of the container
- The last row "floats" left
My question is kind of similar to How to align left last row/line in multiple line flexbox, but I specifically want to use %s for the "columns" — I think it's neater and it means I know I'm going to have, say 3 columns in a row if I use a % like 32.5%
I'm almost there, but the last line is being thrown out because of the justify-content property. I'd like the last row to be "floated" left:
Code
It's easier to see my code in the jsbin above, but for the sake of preservation, here is a small snapshot:
<div id="flexbox">
<div class="column">
<img src="http://placehold.it/350x150" title="" alt="" />
</div>
<div class="column">
<p class="product-title">Decorated Pink High Heels</p>
<p class="product-price">$25.99</p>
<p class="product-title">Decorated Pink High Heels</p>
</div>
</div>
CSS
* {
box-sizing: border-box;
}
#flexbox {
display: flex;
flex-flow: row wrap;
width: 100%;
justify-content: space-between;
border: 3px solid black;
}
#flexbox .column {
width: 22%;
margin-bottom: 30px;
background-color: red;
}
img {
max-width: 100%;
}
I don't think this exact solution can be achieved with Flexbox, but you can use advanced selectors instead like this http://jsbin.com/acejes/14/edit