Grid Simple
grid-simple
uses CSS Grid to create customizable grids. Use --cols
to change the number of columns created by grid-simple
.
Simple, Elegant, and Customizable Grid
Create flexible grids with ease. Just use the [--cols]
variable to specify the number of columns you want.
<!-- 2 Columns --><div class="grid-simple [--cols:2]"> <div>...</div> <div>...</div></div>
<!-- 3 Columns --><div class="grid-simple [--cols:3]"> <div>...</div> <div>...</div> <div>...</div></div>
No minmax nonsense
grid-simple
includes minmax
declarations so you don’t have to. Grid items will never overflow (unless you want them to).
Children can span any number of columns
Just change the --span
variable to change the number of columns a child spans. All children span 1 column by default.
<div class="grid-simple [--cols:6]"> <div>...</div> <div class="[--span:2]">...</div> <div class="[--span:3]">...</div></div>
Excess items automatically flow to the next row
If the child [--span]
causes it to exceed the number of columns, it will automatically flow to the next row.
Dense supported
Use dense
if you wish to fill up spaces with smaller items that come afterwards.
<div class="grid-simple [--cols:6] dense"> ...</div>
Responsive grids are super easy
Use Tailwind responsive modifiers to update --cols
and --span
on the fly to make responsive grids — without context-switching by leaving your HTML!
<div class="grid-simple md:[--cols:2] lg:[--cols:3]"> ...</div>
Basic Usage
Using grid-simple
is easy. Just use [--cols]
to specify the number of columns you want for your grid!
<div class="grid-simple [--cols:2]"> <div>...</div> <div>...</div></div>
Changing the gap between grid items
Change the gap between grid items with the gap
property or the --gap
variable. The difference is --gap
is automatically inherited from ancestor elements while gap
is not.
<div class="grid-simple [--cols:2] gap-8"> <div>...</div> <div>...</div></div>
Spanning multiple columns
Grid items can span multiple columns by using the --span
variable. The default value is 1
.
<div class="grid-simple [--cols:6]"> <div>...</div> <div class="[--span:2]">...</div> <div class="[--span:3]">...</div></div>
Dense
You can use dense
to make the grid items fill in the empty spaces left by larger grid items.
<div class="grid-simple [--cols:6] dense"> <div>...</div> <div class="[--span:2]">...</div> <div class="[--span:4]">...</div> <div class="[--span:2]">...</div> <div>...</div></div>
Responsive Behaviour
grid-simple
lets you change the number of columns easily with Tailwind responsive modifiers. Resize the following demo to see this in action!
<div class="grid-simple md:[--cols:2] lg:[--cols:3]"> <div>...</div> <div>...</div> <div>...</div> <div>...</div> <div>...</div> <div>...</div></div>
Responsive spans
You can also change --span
in addition to changing --cols
. Below is an example where we change --span
and kept --cols
the same.
<div class="grid-simple [--cols:6]"> <div class="[--span:2] @bp6:[--span:1]">...</div> <div class="[--span:2] @bp6:[--span:1]">...</div></div>
Basic Usage
Using grid-simple
is easy. Just use [--cols]
to specify the number of columns you want for your grid!
<div class="grid-simple [--cols:2]"> <div>...</div> <div>...</div></div>
Changing the gap between grid items
Change the gap between grid items with the gap
property or the --gap
variable. The difference is --gap
is automatically inherited from ancestor elements while gap
is not.
<div class="grid-simple [--cols:2] gap-8"> <div>...</div> <div>...</div></div>
Spanning multiple columns
Grid items can span multiple columns by using the --span
variable. The default value is 1
.
<div class="grid-simple [--cols:6]"> <div>...</div> <div class="[--span:2]">...</div> <div class="[--span:3]">...</div></div>
Dense
You can use dense
to make the grid items fill in the empty spaces left by larger grid items.
<div class="grid-simple [--cols:6] dense"> <div>...</div> <div class="[--span:2]">...</div> <div class="[--span:4]">...</div> <div class="[--span:2]">...</div> <div>...</div></div>
Responsive Behaviour
grid-simple
lets you change the number of columns easily with Tailwind responsive modifiers. Resize the following demo to see this in action!
<div class="grid-simple md:[--cols:2] lg:[--cols:3]"> <div>...</div> <div>...</div> <div>...</div> <div>...</div> <div>...</div> <div>...</div></div>
Responsive spans
You can also change --span
in addition to changing --cols
. Below is an example where we change --span
and kept --cols
the same.
<div class="grid-simple [--cols:6]"> <div class="[--span:2] @bp6:[--span:1]">...</div> <div class="[--span:2] @bp6:[--span:1]">...</div></div>
Please purchase a license to view this content
This content is part of our premium documentation. To access it, you'll need to have an active license for one of these products.
If you already have a license, please login to access this content.
The astro-island
and astro-slot
selectors help to alleviate styling frustrations when using Astro.
.grid-simple { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: var(--gap-y, var(--gap)) var(--gap-x, var(--gap)); max-width: 100%;
> *, > *:where(.contents) > *, > *:where(astro-island, astro-slot) > * { grid-column: var(--colstart) / span var(--span); grid-row: var(--rowstart) / span var(--rowspan); max-width: 100%; }}
The astro-island
and astro-slot
selectors help to alleviate styling frustrations when using Astro.
.grid-simple { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: var(--gap-y, var(--gap)) var(--gap-x, var(--gap)); max-width: 100%;
> *, > *:where(.contents) > *, > *:where(astro-island, astro-slot) > * { grid-column: var(--colstart) / span var(--span); grid-row: var(--rowstart) / span var(--rowspan); max-width: 100%; }}
Please purchase a license to view this content
This content is part of our premium documentation. To access it, you'll need to have an active license for one of these products.
If you already have a license, please login to access this content.
Simple Grid CSS Variables
CSS Variable | Default | Description |
---|---|---|
--gap-x | 1rlh | Gap between columns |
--gap-y | 1rlh | Gap between rows |
--gap | 1rlh | Gap between columms and rows |
--cols | 1 | Number of columns |
Children CSS Variables
CSS Variable | Default | Description |
---|---|---|
--span | 1 | Number of columns that the child should occupy. |
--rowspan | 1 | Number of rows the child should occupy. |
--colstart | auto | Column start position. |
--rowstart | auto | Row start position. |
Simple Grid CSS Variables
CSS Variable | Default | Description |
---|---|---|
--gap-x | 1rlh | Gap between columns |
--gap-y | 1rlh | Gap between rows |
--gap | 1rlh | Gap between columms and rows |
--cols | 1 | Number of columns |
Children CSS Variables
CSS Variable | Default | Description |
---|---|---|
--span | 1 | Number of columns that the child should occupy. |
--rowspan | 1 | Number of rows the child should occupy. |
--colstart | auto | Column start position. |
--rowstart | auto | Row start position. |
Please purchase a license to view this content
This content is part of our premium documentation. To access it, you'll need to have an active license for one of these products.
If you already have a license, please login to access this content.