How to span to the last column in an implicit grid?

Why shouldn't it work on implicit grids?

Because we can easily run on undefined cases1 or a cyclic dependency. If it was the implicit grid, it means that we need to first place all the others element to identify the implicit grid then we place our element BUT if we place our element we will obtain another implicit grid so technically you cannot know the implicit grid without placing the element.

The idea behind the implicit grid is to place the element that doesn't have anything defined for their placement automatically after placing the ones with known places.


You can overcome this by using some hacks either for row or column:

Stretch an element to the end of the automatically calculated grid, not just the explicit grid

Forcing a column to be empty in a responsive grid layout


1 A basic example:

.grid {
  display: grid;
  grid-template-columns: 50px;
  grid-gap: 5px;
  grid-auto-flow: column;
  grid-auto-columns:50px;
}

.grid>span {
  height: 50px;
  background: red;
}

.grid>span.place {
  grid-column: 1 / -1;
  background: blue;
}
<div class="grid">
  <span></span>
  <span class="place"></span>
</div>

Logically we will first place the blue span in the explicit grid then the we place the red one automatically to obtain an implicit grid of 2 columns.

Considering your logic I have the following cases:

  1. I change the place of the blue so it takes the two columns which will move the red to a third one. I repeat again (an infinite loop)

  2. I change the place of the blue so it takes two columns and overlap the red one (not really logical and intuitive)

  3. I don't place the blue but I first place the red then I either overlap the red one (not logical) or I place the blue in that column and push the red to anoher one and I get back to (1)

Tags:

Css

Css Grid