Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using negative integers with implicit rows in CSS Grid

Tags:

css

css-grid

I am trying to make a simple sidebar layout with a flat HTML structure, in which the first <aside> element fills in the 1st column completely.

My problem is, that the negative row end value seems to not work for the implicitly created rows for all my elements in the 2nd column.

Expected:

enter image description here

Actual:

enter image description here

Below is a runnable code snippet that illustrates the problem.

article {
  display: grid;
  grid-template-columns: 200px 1fr;
  background: gray;
}

aside {
  grid-row: 1/-1;
  grid-column: 1/2;
  background: pink;
}

section {
  grid-column: 2/3;
  background: yellow;
}
<article>
  <aside>In the left column (top to bottom)</aside>
  <section>In the right column</section>
  <section>In the right column</section>
  <section>In the right column</section>
</article>
like image 898
warpech Avatar asked Mar 02 '18 17:03

warpech


1 Answers

You can only use negative integers in an explicit grid.

See the Grid spec here:

7.1. The Explicit Grid

Numeric indexes in the grid-placement properties count from the edges of the explicit grid. Positive indexes count from the start side (starting from 1 for the start-most explicit line), while negative indexes count from the end side (starting from -1 for the end-most explicit line).

and here...

8.3. Line-based Placement: the grid-row-start, grid-column-start, grid-row-end, and grid-column-end properties

If a negative integer is given, it instead counts in reverse, starting from the end edge of the explicit grid.

Making a grid area span an entire column / row, including implicit tracks, when the number of tracks in the grid is unknown, is not possible in CSS Grid Level 1, unless you want to try to hack it.

like image 78
Michael Benjamin Avatar answered Sep 20 '22 06:09

Michael Benjamin