Reputation: 2198
I want to align some div's with same class name in a row using css grid layout. when i tried all div are aligned in top of another one. How to achieve this using css grid layout.
.front{
grid-area: front;
}
.accountcontainer{
display: grid;
margin: 0 10px;
background: #ffffff;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-template-areas:
"front front front front";
margin-bottom: 20px;
}
Upvotes: 1
Views: 2460
Reputation: 115045
Don't use grid-area
Just specify the grid-row
for that class.
Note the number of divs with that class MUST be the same as (or less than) the number of columns.
.container {
display: grid;
margin: 10px auto;
background: #ffffff;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-auto-flow: rows;
margin-bottom: 20px;
border: 1px solid grey;
}
.item {
height: 60px;
background: pink;
display: flex;
justify-content: center;
align-items: center;
color: whitesmoke;
border: 1px solid red;
}
.item.front {
background: rebeccapurple;
}
.front {
grid-row: 1;
}
<div class="container">
<div class="item front">1</div>
<div class="item front">2</div>
<div class="item"></div>
<div class="item front">3</div>
<div class="item front">4</div>
<div class="item"></div>
<div class="item"></div>
</div>
Upvotes: 4