Why i have to declare the grid-column before the row. the

Tell us what’s happening:

Is just a question about this grid cell. The 5th cell in the grid, if i don’t put the grid-column first, 5th cell will take the place of the 4. Why is that?

Your code so far


<style>
.item1{background:LightSkyBlue;}
.item2{background:LightSalmon;}
.item3{background:PaleTurquoise;}
.item4{background:LightPink;}

.item5 {
  background: PaleGreen;
  grid-column: 2 / 3;
  /* Only change code below this line */
  grid-row: 2 / 4;
  /* Only change code above this line */
}

.container {
  font-size: 40px;
  min-height: 300px;
  width: 100%;
  background: LightGray;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  grid-gap: 10px;
}
</style>

<div class="container">
<div class="item1">1</div>
<div class="item2">2</div>
<div class="item3">3</div>
<div class="item4">4</div>
<div class="item5">5</div>
</div>

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:83.0) Gecko/20100101 Firefox/83.0.

Challenge: Use grid-row to Control Spacing

Link to the challenge:

That is a good question and it’s not super intuitive. I believe it has to do with how auto placed items and placed items interact (placement order).

MDN: Auto-placement in CSS Grid Layout Items with placement properties

The first thing grid will do is place any items that have a position. In the example below I have 12 grid items. Item 2 and item 5 have been placed using line based placement on the grid. You can see how those items are placed and the other items then auto-place in the spaces. The auto-placed items will place themselves before the placed items in DOM order, they don’t start after the position of a placed item that comes before them.

Here an article that tries to explain it as well.