html - Achieving a certain grid using flexbox -
this question has answer here:
i'm using flexbox create grid website. grid used articles archive, , should display 3 articles per row margin between each article.
the problem is: need article boxes start @ beginning of row , end @ end of row. obvious thing use justify-content: space-between;
, did. this, in addition flex-wrap: wrap
created grid needed. until has odd number of articles. justify-content
property left blank space @ middle of row, can see in following example:
http://codepen.io/naxon/pen/nbnxvj
it important me, no matter width of container is, items start @ beginning , end the end.
how can achieve this?
flexbox doesn't support inter-item padding can fake calc()
, margin
. codepen
.container { width: 800px; height: 800px; background-color: blue; display: flex; flex-wrap: wrap; /*justify-content: space-between;*/ } .item { width: 150px; height: 150px; background-color: green; /* margins */ margin-left: 10px; /* figure out width taking margins account */ flex-basis: calc((100% - 20px) / 3); } /* clear margin on every third item starting first */ .item:nth-child(3n+1) { margin-left: 0; }
<div class="container"> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> <div class="item"></div> </div>
Comments
Post a Comment