I am trying to achieve the following layout using CSS grid...
I currently use flex to generate it like this..
.row1 {
display:flex;
}
.row1 .item {
background:red;
width:50%;
padding:20px;
margin:10px;
color:white;
text-align:center;
}
.row2 {
display:flex;
}
.row2 .item {
color:white;
text-align:center;
background:red;
width:33%;
padding:20px;
margin:10px;
}
<div class="row1">
<div class="item">
Item
</div>
<div class="item">
Item
</div>
</div>
<div class="row2">
<div class="item">
Item
</div>
<div class="item">
Item
</div>
<div class="item">
Item
</div>
</div>
this but am trying to convert it, how could I make the CSS grid version of it repeat in this pattern for dynamic content?
With
display:grid
, a single container is enough. to repeat the pattern, you can use thenth-child(xn)
selector.example
Some reading to go farther and handle yourself your next grid templates : about nth-child https://css-tricks.com/how-nth-child-works/
and grid : https://css-tricks.com/snippets/css/complete-guide-grid/ & https://gridbyexample.com/
This CSS snippet, is easiest change you can start with..