Subgrid
Subgrid
lets you use CSS Subgrid easily without the configuration headaches.
-->
Subgrid
lets you use CSS Subgrid easily without the configuration headaches.
No need to define the subgrid
on grid-template-columns
, grid-template-rows
, inheriting gap
, and all the configuration nonsense. We do that all for you with the Subgrid
class.
You only need subgrid for one direction most of the time — so we created Subgrid-columns
and Subgrid-rows
to cater to that use case. But if you need to subgrids in both directions, we’ve got that covered too.
Just use Subgrid-rows
and specify the number of elements in the subgrid as the --rowspan
variable and everything will be neatly arranged.
Subgrid-columns
let you use the same number of columns, but create multiple rows — while the parent still thinks it’s one!
Use --ispan
to configure the number of columns the
grandchild element should occupy.
Go crazy and creative and make as many whacky grids as you would like. Subgrid
can support them all — and still keep you sane.
This is a pretty complex 10-column grid. It’s created with 2 nested subgrid-column
Subgrid
lets you create use a grid that a parent element has created. There are three Subgrid
classes:
Subgrid-columns
: Creates subgrid for columnsSubgrid-rows
: Creates subgrid for rowsSubgrid
: Creates subgrid for both columns and rowsAll Subgrid
classes are to be used on children grid items.
By far, the most common use case for Subgrid
is Subgrid-rows
, but we’ll start the guide with Subgrid-columns
because its easier to grasp.
Subrgid-columns
lets you use Subgrid only for columns. To use Subgrid-columns
, you must:
--span
to the element with subgrid so it knows the number of columns it should adopt from the parent grid.--ispan
to define the number of columns in the grandchild element.Both --span
and --ispan
defaults to 1
.
You won’t need Subgrid-columns
most of the time because you can just use display: contents
on the parent element and --span
on the grandchild element. This is easier (and you use lesser keystrokes too).
You would, however, use Subgrid-columns
if you want to create more than 1 row of items in the Subgrid
, but retain the whole element as 1 row in the parent grid — this is not doable with display:contents
.
If that sounds confusing, the following example may make sense.
If you want to nest Subgrid-columns
in another Subgrid
, you must do the same thing as before:
--span
to specify the number of columns the nested Subgrid column should occupy.--ispan
to specify the number of columns the eventual grandchild should specify.Subgrid-rows
is probably the reason most people use CSS Subgrid. It lets you place grand-children elements on the rows of the parent grid — so grandchildren elements can be neatly arranged, like this:
To use Subgrid-rows
, you must:
--rowspan
to specify the number of rows the subgrid should occupy.--irowspan
to specify the number of rows the grandchild should occupy.Both --rowspan
and --irowspan
defaults to 1.
The easiest way to use Subgrid-rows
is to structure your HTML such that you --rowspan
corresponds to the number of elements in the subgrid. When you do this, you can omit --irowspan
completely.
Here’s the code you need to create the above example.
If you cannot structure your HTML according to the number of elements in --rowspan
, the next easiest way is to create another Subgrid-rows
and specify the nested --rowspan
.
You can adjust --irowspan
if you’re building an irregular grid that contains different rows of items in the subgrid. This can be used to create really fancy grids!
Subgrid
lets you create subgrids in both directions — columns and rows. Just heed the above rules of Subgrid-columns
and Subgrid-rows
and you’re good to go with this.
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
Subgrid
lets you create use a grid that a parent element has created. There are three Subgrid
classes:
Subgrid-columns
: Creates subgrid for columnsSubgrid-rows
: Creates subgrid for rowsSubgrid
: Creates subgrid for both columns and rowsAll Subgrid
classes are to be used on children grid items.
By far, the most common use case for Subgrid
is Subgrid-rows
, but we’ll start the guide with Subgrid-columns
because its easier to grasp.
Subrgid-columns
lets you use Subgrid only for columns. To use Subgrid-columns
, you must:
--span
to the element with subgrid so it knows the number of columns it should adopt from the parent grid.--ispan
to define the number of columns in the grandchild element.Both --span
and --ispan
defaults to 1
.
You won’t need Subgrid-columns
most of the time because you can just use display: contents
on the parent element and --span
on the grandchild element. This is easier (and you use lesser keystrokes too).
You would, however, use Subgrid-columns
if you want to create more than 1 row of items in the Subgrid
, but retain the whole element as 1 row in the parent grid — this is not doable with display:contents
.
If that sounds confusing, the following example may make sense.
If you want to nest Subgrid-columns
in another Subgrid
, you must do the same thing as before:
--span
to specify the number of columns the nested Subgrid column should occupy.--ispan
to specify the number of columns the eventual grandchild should specify.Subgrid-rows
is probably the reason most people use CSS Subgrid. It lets you place grand-children elements on the rows of the parent grid — so grandchildren elements can be neatly arranged, like this:
To use Subgrid-rows
, you must:
--rowspan
to specify the number of rows the subgrid should occupy.--irowspan
to specify the number of rows the grandchild should occupy.Both --rowspan
and --irowspan
defaults to 1.
The easiest way to use Subgrid-rows
is to structure your HTML such that you --rowspan
corresponds to the number of elements in the subgrid. When you do this, you can omit --irowspan
completely.
Here’s the code you need to create the above example.
If you cannot structure your HTML according to the number of elements in --rowspan
, the next easiest way is to create another Subgrid-rows
and specify the nested --rowspan
.
You can adjust --irowspan
if you’re building an irregular grid that contains different rows of items in the subgrid. This can be used to create really fancy grids!
Subgrid
lets you create subgrids in both directions — columns and rows. Just heed the above rules of Subgrid-columns
and Subgrid-rows
and you’re good to go with this.
Here’s the CSS for Subgrid
.
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
Here’s the CSS for Subgrid
.
Class | Description |
---|---|
Subgrid | Sets both grid-template-columns and grid-template-rows to subgrid along with other enhancements |
Subgrid-columns | Sets grid-template-columns to subgrid along with other enhancements |
Subgrid-rows | Sets grid-template-rows to subgrid along with other enhancements |
Variable | Default | Description |
---|---|---|
--span | 1 | Number of columns for the subgrid to span |
--ispan | 1 | Number of columns for grandchild items to span |
--rowspan | 1 | Number of rows for the subgrid to span |
--irowspan | 1 | Number of rows for the grandchild item to span |
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
Class | Description |
---|---|
Subgrid | Sets both grid-template-columns and grid-template-rows to subgrid along with other enhancements |
Subgrid-columns | Sets grid-template-columns to subgrid along with other enhancements |
Subgrid-rows | Sets grid-template-rows to subgrid along with other enhancements |
Variable | Default | Description |
---|---|---|
--span | 1 | Number of columns for the subgrid to span |
--ispan | 1 | Number of columns for grandchild items to span |
--rowspan | 1 | Number of rows for the subgrid to span |
--irowspan | 1 | Number of rows for the grandchild item to span |