1. sds-grid()
A SCSS mixin to turn an element into a CSS Grid container with equally divided columns.
Structure
Much like the CSS Flexbox, CSS Grid is not applied directly to the elements you wish to position. Instead, Grid and most of its complementary CSS properties are declared on the "parent" of the elements to be affected. The following example illustrates this.
<div class="parent">
<div class="column"></div>
<div class="column"></div>
<div class="column"></div>
<div class="column"></div>
</div>
// Correct grid application
.parent {
display: grid;
}
// Incorrect
.parent {
.column{
display: grid;
}
}
Implementation
This mixin is one of the most commonly used because it offers developers an easy and automatic way of implementing {n
} number of columns while also controlling the space between them.
@include sds-grid($columns, $gap);
This mixin accepts two parameters: $columns
and $gap
. The $columns
parameter is required, and should be a number that expresses the amount of columns desired in the grid (it's important to reference). The $gap
parameter is optional, and its default value is set to 0. This parameter accepts a number value that should be specified in measurable units such a pixels, percentages, rem, etc.
Basic implementation of sds-grid
:
.parent {
@include sds-grid(4);
.column {
border: 1px solid sds-color(red, 80);
}
}

Providing a value for the $gap
parameter will control the space between columns:
.parent {
@include sds-grid(4, 8px);
.column {
border: 1px solid sds-color(red, 80);
}
}

When specifying a value for the $gap
parameter, it is strongly recommended to use Sipster's sds-spc()
function for most instances. The following example illustrates this method.
.parent {
@include sds-grid(4, sds-spc(8));
}
which compiles to:
.parent {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-gap: 0.5rem;
}
Last updated