Is it possible to alternately color flexbox rows with pure CSS?
With the code below, I'm able to use nth-child
to alternately color individual flex items. Is there a way to alternately color the virtual flex rows created by the CSS flex using pure CSS?
I'm giving my flex items here a fixed height and width, but in reality they could be any size.
.flexbox{
display:flex;
flex-wrap: wrap;
width: 600px;
}
.flex-item{
border: 1px solid black;
height: 150px;
width:150px;
}
.flex-item:nth-child(odd){
background-color: #ddd;
}
.flex-item:nth-child(2n - 1){
height:200px;
}
<div class="flexbox">
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
<div class="flex-item"></div>
</div>