Let's say I'm using a flexbox container with flex-direction:row
and flex-wrap:wrap
.
Depending on the size of the browser window, I might have 2, 3, 4 or more items in each row.
I want to put a grey background in the items in every other row, mimicking a table layout. Is there an easy way to do this?
Example fiddle here: https://jsfiddle.net/mqf7nouc/1/
HTML:
<div class="container">
<div class="item">
item 1
</div>
<div class="item">
item 2
</div>
<div class="item">
item 3
</div>
<div class="item">
item 4
</div>
<div class="item">
item 5
</div>
<div class="item">
item 6
</div>
<div class="item">
item 7
</div>
</div>
CSS:
.container {
display:flex;
flex-direction:row;
flex-wrap:wrap;
}
.item {
height:50px;
width:100px;
text-align:center;
vertical-align:middle;
line-height:50px;
border:1px solid black;
margin:5px;
}