Grid
Grid display and columns and rows utilities with module mixins for responsive modifiers.
Utilities (anchor)
| Utility class | Property values |
|---|---|
| .grid | display: grid |
| .grid-inline | display: inline-grid |
| .grid-revert | display: revert |
| Utility class | Property values |
|---|---|
| .grid-columns, .grid-autofit, [class*=grid-columns-], [class*=grid-autofit-] |
--rows: repeat(var(--gtr, 1), minmax(0, 1fr)) display: grid; grid-template-rows: var(--rows); |
| .grid-columns | grid-template-columns: repeat(var(--cols, 1), minmax(0, var(--gmax, 1fr))); |
| .grid-autofit | grid-template-columns: repeat(auto-fit, minmax(var(--gmin, 256px), 1fr)); |
| Column classes | |
| .g-1 | --cols: 1 |
| .g-2 | --cols: 2 |
| .g-3 | --cols: 3 |
| .g-4 | --cols: 4 |
| .g-5 | --cols: 5 |
| .g-6 | --cols: 6 |
| .g-7 | --cols: 7 |
| .g-8 | --cols: 8 |
| .g-9 | --cols: 9 |
| .g-10 | --cols: 10 |
| .g-11 | --cols: 1 |
| .g-12 | --cols: 12 |
| Utility class | Property values |
|---|---|
| Grid columns | |
| .col-1 | grid-column: auto/span 1 |
| .col-2 | grid-column: auto/span 2 |
| .col-3 | grid-column: auto/span 3 |
| .col-4 | grid-column: auto/span 4 |
| .col-5 | grid-column: auto/span 5 |
| .col-6 | grid-column: auto/span 6 |
| .col-7 | grid-column: auto/span 7 |
| .col-8 | grid-column: auto/span 8 |
| .col-9 | grid-column: auto/span 9 |
| .col-10 | grid-column: auto/span 10 |
| .col-11 | grid-column: auto/span 11 |
| .col-12 | grid-column: auto/span 12 |
| Grid rows | |
| .row-1 | grid-row: auto/span 1 |
| .row-2 | grid-row: auto/span 2 |
| .row-3 | grid-row: auto/span 3 |
| .row-4 | grid-row: auto/span 4 |
| .row-5 | grid-row: auto/span 5 |
| .row-6 | grid-row: auto/span 6 |
Column and row start and end utilities
| Utility class | Property values |
|---|---|
| Grid column start | |
| .col-start-1 | grid-column-start: 1 |
| .col-start-2 | grid-column-start: 2 |
| .col-start-3 | grid-column-start: 3 |
| .col-start-4 | grid-column-start: 4 |
| .col-start-5 | grid-column-start: 5 |
| .col-start-6 | grid-column-start: 6 |
| .col-start-7 | grid-column-start: 7 |
| .col-start-8 | grid-column-start: 8 |
| .col-start-9 | grid-column-start: 9 |
| .col-start-10 | grid-column-start: 10 |
| .col-start-11 | grid-column-start: 11 |
| Grid column end | |
| .col-end-1 | grid-column-end: 1 |
| .col-end-2 | grid-column-end: 2 |
| .col-end-3 | grid-column-end: 3 |
| .col-end-4 | grid-column-end: 4 |
| .col-end-5 | grid-column-end: 5 |
| .col-end-6 | grid-column-end: 6 |
| .col-end-7 | grid-column-end: 7 |
| .col-end-8 | grid-column-end: 8 |
| .col-end-9 | grid-column-end: 9 |
| .col-end-10 | grid-column-end: 10 |
| .col-end-11 | grid-column-end: 11 |
| .col-end-12 | grid-column-end: 12 |
| Grid row start | |
| .row-start-1 | grid-row-start: 1 |
| .row-start-2 | grid-row-start: 2 |
| .row-start-3 | grid-row-start: 3 |
| .row-start-4 | grid-row-start: 4 |
| .row-start-5 | grid-row-start: 5 |
| Grid row end | |
| .row-end-1 | grid-row-end: 1 |
| .row-end-2 | grid-row-end: 2 |
| .row-end-3 | grid-row-end: 3 |
| .row-end-4 | grid-row-end: 4 |
| .row-end-5 | grid-row-end: 5 |
| .row-end-6 | grid-row-end: 6 |
Responsive mixins (anchor)
Responsive modifier mixins are provided to include where required in custom breakpoints, the utilities available use the following modifier class naming convention:
.grid
.grid-xxl
.grid-xl
.grid-lg
.grid-md
.grid-sm
.grid-xs
.grid-xxsExamples (anchor)
Grid columns (anchor)
Grid columns are applied to a container to automatically create a checkerboard grid of child elements:
<div class="grid-columns g-4 g-2-md gap-2 mb-3">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
The default fraction widths (1fr) used ensure the column sizes remains fixed regardless of content:
<div class="grid-columns g-4 g-2-xs gap-2">
<div>1</div>
<div>The quick brown fox jumps over the lazy dog.</div>
<div>3</div>
<div>4</div>
</div>But you can also change the widths to auto inline so the columns stretch to match the content within:
<div class="grid-columns g-4 g-2-xs gap-2" style="--gmax:auto;">
...
</div>Auto-fit columns (anchor)
New v1.5.0. The .grid-autofit columns include a (customizable) default minimum width of 300px (18.75rem) designed to automatically wrap columns responsively without custom breakpoint modifiers:
<div class="grid-autofit gap-2 mb-3">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>The default width can be customized using CSS variables inline:
<div class="grid-autofit gap-2" style="--gmin:220px;">
...
</div>Grid layouts (anchor)
The grid layout utilities are applied to child elements to enable creating basic page and content layouts:
<div class="grid-columns g-12 gap-2">
<div class="col-3">.col-3</div>
<div class="col-6">.col-6</div>
<div class="col-3">.col-3</div>
</div>Grid row classes provide scope for more complex layouts, and grid start and end utilities enable designing content flow to match visual positioning within the grid:
<div class="grid-columns g-12 gap-2">
<div class="col-3 row-2">1</div>
<div class="col-6">2</div>
<div class="col-start-4 col-end-10">3</div>
<div class="col-3 col-start-10 row-start-1 row-end-3">4</div>
</div>Use the responsive classes to change grid patterns at specific breakpoints:
<div class="grid-columns g-12 gap-2 mb-3">
<div class="col-3 row-2-lg col-12-xs row-1-xs">1</div>
<div class="col-6 col-9-lg col-12-xs">2</div>
<div class="col-3 col-9-lg col-12-xs">3</div>
</div>
You can also use other values instead of 12 to define the default grid pattern:
<div class="grid-columns g-9 gap-2">
<div class="col-2">.col-2</div>
<div class="col-5">.col-5</div>
<div class="col-2">.col-2</div>
</div>
Using the module (anchor)
Load StyleMods as demonstrated (change file path as required) then include the Sass mixin anywhere below.
Each set of utilities can be included individually:
@use "stylemods/scss" as *;
@include grid-display-css;
@include grid-columns-css;
@include grid-layouts-css; // Requires grid-columns
@media (width < 480px) {
@include grid-display-sm-css;
@include grid-columns-sm-css;
@include grid-layouts-sm-css
}Or included grouped in a single mixin:
@use "stylemods/scss" as *;
@include grid-css;
@media (width < 480px) {
@include grid-sm-css;
}See the using modules page for more information.
Using the framework (anchor)
Using the recommended custom setup enable the styles (and required breakpoints) in an overrides document:
@use "stylemods/scss/configuration" as *;
$enable-grid: true;
$enable-grid-columns: true;
$enable-grid-layouts: true; // Requires grid-columns
$enable-grid-sm: true;
$enable-grid-columns-sm: true;
$enable-grid-layouts-sm: true;Include the overrides and the framework styles with your custom document for compiling the framework:
@use "overrides";
@use "stylemods/scss/stylemods";See using the framework for more information.
Source code (anchor)
The Grid source file is included with the layout module files, you can view the source code from the latest release (v1.5.0) via the Github link below.
- Source document
- stylemods/scss/layout/grid.scss
- View on Github
- https://github.com/pmbrown/StyleMods/blob/main/scss/layout/grid.scss
Shared documentation about how to customize the default property values for the styles using the Sass and CSS variables is provided on the customizing page.