Items that span all columns/rows using CSS grid layout

Marlius picture Marlius · Feb 15, 2017 · Viewed 25.7k times · Source

With the CSS Grid Layout Module soon shipping in Firefox and Chrome, I thought that I'd try to get a handle of how to use it.

I've tried to create a simple grid with one item a spanning the left side of all of the rows, with the other items (b, c, d, e, etc.) spanning the right side of individual rows. The amount of items spanning the right side of the rows is variable, so there might be any combination of b, c, d, e, etc., so I'm using the grid-auto-rows property. As such, I cannot define a fixed number of rows for a to span, but I would like a to span all available rows.

What should I do to make a span all rows without knowing how many rows there will end up being?

Answer

lehoang picture lehoang · May 30, 2018

I had the same situation and found a clean solution.

Instead of using a huge row span value, try:

    grid-column: 1/-1;

As negative number counts from the right, this code specifies the grid-column to the end of the last column.

Note: In case this doesn't apply, check Jonny Green's solution in the below comment.