0

I want to center my 7 images, I set 4 columns for each row:

image

The code is like this :

display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));

Instead I want to set 4 columns in the first row, and 3 items in the second row, so it will look like centered. How to do that ?

Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
Jaacoubi
  • 31
  • 2

1 Answers1

0

You should use flexbox for this type of layout. CSS Grid isn't the best solution for centering last rows like that. This is what flexbox was made for.

.grid {
  display: flex;
  flex-flow: row wrap;
  justify-content: center;
  align-items: center;
  padding: 40px;
}

.item {
  height: 30px;
  width: 200px;
  margin: 10px;
  background: tomato;
}
<div class="grid">
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
  <div class="item"></div>
</div>
offoffoff
  • 204
  • 4