Grid
A simple grid based layout component.
A simple grid based layout component.
npm install @vrembem/grid@use "@vrembem/grid";Grid is built as a Sass module. Sass options are used to control CSS output, while design token CSS variables control the styling of the component. Below are the available configuration options.
Grid comes with the following Sass configuration options that can be set using either the config module or Sass with clause methods.
@use "@vrembem/grid" with (
$config: (
// Map for outputting grid--cols-[num] modifier and col-[num] utility variants
// @type map
"grid-cols": (
"breakpoints": true,
"default": 1,
"total": 6
),
// Map for outputting grid--rows-[num] modifier and row-[num] utility variants
// @type map
"grid-rows": (
"breakpoints": true,
"default": 1,
"total": 6
),
// Map for outputting the grid--gap-[key] modifier variants
// @type map
"grid-gap": (
"breakpoints": true,
"default": calc(tokens.get("spacing") * 8),
"0": 0,
"xs": calc(tokens.get("spacing") * 2),
"sm": calc(tokens.get("spacing") * 4),
"md": calc(tokens.get("spacing") * 8),
"lg": calc(tokens.get("spacing") * 12),
"xl": calc(tokens.get("spacing") * 16)
),
// Map for outputting the grid--flow-[key] modifier variants
// @type map
"grid-flow": (
"default": dense,
"row": row,
"col": column,
"row-dense": row dense,
"col-dense": column dense
)
)
);Grid uses design token CSS variables in a reference and fallback pattern. Variables are referenced in the component's styles but are not directly defined; instead, they are provided with sensible fallbacks.
| Variable | Fallback |
|---|---|
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
There are no variables that match your search.
The most basic implementation of the grid layout consists of the grid container and it's children (grid items). Apply the grid class to the desired grid container with an optional grid--cols-[num] modifier to create a grid layout.
<div class="grid grid--cols-3">
<div>...</div>
<div>...</div>
<div>...</div>
</div>Also available is the grid--inline modifier. This sets the display property to inline-grid instead of grid.
<div class="grid grid--inline grid--cols-3">
<div>...</div>
<div>...</div>
<div>...</div>
</div>By default the grid class only defines a single column. To add additional columns to the grid layout, use the grid--cols-[num] modifiers. The number of variants available is controlled by the grid-cols config option (default: 6).
<div class="grid grid--cols-3">
...
</div>Available variants
grid--cols-1grid--cols-2grid--cols-3grid--cols-4grid--cols-5grid--cols-6These modifiers come with media breakpoint variants. This allows changing styles based on a specific breakpoint key in the breakpoints config options map.
Current view-port width: ...
<div class="grid lg:grid--cols-3">
...
</div>Available variants
xs:grid--cols-[num]sm:grid--cols-[num]md:grid--cols-[num]lg:grid--cols-[num]xl:grid--cols-[num]By default the grid class only defines a single row. To add additional rows to the grid layout, use the grid--rows-[num] modifiers. The number of variants available is controlled by the grid-rows config option (default: 6).
<div class="grid grid--cols-2 grid--rows-2">
<div class="row-full">...</div>
<div>...</div>
</div>Available variants
grid--rows-1grid--rows-2grid--rows-3grid--rows-4grid--rows-5grid--rows-6These modifiers come with media breakpoint variants. This allows changing styles based on a specific breakpoint key in the breakpoints config options map.
Current view-port width: ...
<div class="grid grid--cols-2 lg:grid--rows-2">
<div class="row-full">...</div>
<div>...</div>
</div>Available variants
xs:grid--rows-[num]sm:grid--rows-[num]md:grid--rows-[num]lg:grid--rows-[num]xl:grid--rows-[num]Modifiers used to set the gap property of a grid component. These modifiers are generated using key/value pairs of the grid-gap config options map. The default key sets the provided value on the flex component itself and is not output as a modifier.
<div class="grid grid--cols-2 grid--gap-xs">
...
</div>Available variants
grid--gap-0grid--gap-xsgrid--gap-smgrid--gap-mdgrid--gap-lggrid--gap-xlModifiers to set the column-gap value on a grid component. These modifiers are generated using key/value pairs of the grid-gap config options map.
<div class="grid grid--cols-2 grid--gap-x-xs">
...
</div>Available variants
grid--gap-x-0grid--gap-x-xsgrid--gap-x-smgrid--gap-x-mdgrid--gap-x-lggrid--gap-x-xlModifiers to set the row-gap value on a grid component. These modifiers are generated using key/value pairs of the grid-gap config options map.
<div class="grid grid--cols-2 grid--gap-y-xs">
...
</div>Available variants
grid--gap-y-0grid--gap-y-xsgrid--gap-y-smgrid--gap-y-mdgrid--gap-y-lggrid--gap-y-xlThese modifiers come with media breakpoint variants. This allows changing styles based on a specific breakpoint key in the breakpoints config options map.
Available variants
xs:grid--gap-[key]sm:grid--gap-[key]md:grid--gap-[key]lg:grid--gap-[key]xl:grid--gap-[key]xs:grid--gap-x-[key]sm:grid--gap-x-[key]md:grid--gap-x-[key]lg:grid--gap-x-[key]xl:grid--gap-x-[key]xs:grid--gap-y-[key]sm:grid--gap-y-[key]md:grid--gap-y-[key]lg:grid--gap-y-[key]xl:grid--gap-y-[key]Modifiers used to set the grid-auto-flow property of a grid component. By default, the grid component has auto-flow set to dense. These modifiers are generated using key/value pairs of the grid-flow config options map. The default key sets the provided value on the grid component itself and is not output as a modifier.
<div class="grid grid--cols-3 grid--rows-3 grid--flow-row">
...
</div>Available variants
grid--flow-rowgrid--flow-colgrid--flow-row-densegrid--flow-col-denseGrid utilities are intended to be used directly on the children of a grid component or grid container (elements with display: grid or display: inline-grid). Since these only change a single CSS property, utility classes are used instead of BEM element classes.
A utility used to control the grid-column property which handles a grid item's size and location within a grid column. The number of variants available is controlled by the grid-cols config option (Default: 6).
<div class="grid grid--cols-6">
<div class="grid-col-3">...</div>
<div>...</div>
<div>...</div>
<div>...</div>
</div>Available variants
grid-col-autogrid-col-1grid-col-2grid-col-3grid-col-4grid-col-5grid-col-6grid-col-fullgrid-col-start-1grid-col-start-2grid-col-start-3grid-col-start-4grid-col-start-5grid-col-start-6grid-col-start-7grid-col-end-1grid-col-end-2grid-col-end-3grid-col-end-4grid-col-end-5grid-col-end-6grid-col-end-7This utility also come with media breakpoint variants. This allows changing styles based on a specific breakpoint key in the breakpoints config options map.
Current view-port width: ...
<div class="grid grid--cols-6">
<div class="grid-col-6 md:grid-col-3 lg:grid-col-2">...</div>
<div class="grid-col-6 md:grid-col-3 lg:grid-col-2">...</div>
<div class="grid-col-3 md:grid-col-6 lg:grid-col-2">...</div>
<div class="grid-col-3 md:grid-col-3 lg:grid-col-3">...</div>
<div class="grid-col-6 md:grid-col-3 lg:grid-col-3">...</div>
</div>Available variants
xs:grid-col-[num]sm:grid-col-[num]md:grid-col-[num]lg:grid-col-[num]xl:grid-col-[num]A utility used to control the grid-row property which handles a grid item's size and location within a grid row. The number of variants available is controlled by the grid-rows config option (Default: 6).
<div class="grid grid--cols-6 grid--rows-6">
<div class="grid-row-2">...</div>
<div>...</div>
<div>...</div>
<div>...</div>
</div>Available variants
grid-row-autogrid-row-1grid-row-2grid-row-3grid-row-4grid-row-5grid-row-6grid-row-fullgrid-row-start-1grid-row-start-2grid-row-start-3grid-row-start-4grid-row-start-5grid-row-start-6grid-row-start-7grid-row-end-1grid-row-end-2grid-row-end-3grid-row-end-4grid-row-end-5grid-row-end-6grid-row-end-7This utility also come with media breakpoint variants. This allows changing styles based on a specific breakpoint key in the breakpoints config options map.
Current view-port width: ...
<div class="grid grid--cols-3 grid--rows-3 grid--flow-col-dense">
<div class="md:grid-row-2 lg:grid-row-3">1</div>
<div class="md:grid-row-2 lg:grid-row-3">2</div>
<div class="md:grid-row-1">3</div>
<div class="md:grid-row-1">4</div>
<div class="md:grid-row-3 lg:grid-row-1">5</div>
</div>Available variants
xs:grid-row-[num]sm:grid-row-[num]md:grid-row-[num]lg:grid-row-[num]xl:grid-row-[num]