Skip to content

Instantly share code, notes, and snippets.

@azinasili
Last active January 18, 2018 18:37
Show Gist options
  • Save azinasili/f6d4a4b577d3ae3096137487f500ef3d to your computer and use it in GitHub Desktop.
Save azinasili/f6d4a4b577d3ae3096137487f500ef3d to your computer and use it in GitHub Desktop.
Create the simplest grid possible using CSS Grid syntax
// Create the simplest grid possible using CSS Grid syntax
// Customize your grid with custom number of items, classnames, and gaps
//
// Example HTML
// <div class="row row-3">
// <div class="col-1"></div>
// <div class="col-1"></div>
// <div class="col-1"></div>
// </div>
$SassGrid: (
numberOfColumns: 10,
rowClassName: 'row',
colClassName: 'col',
gridGap: 1em,
);
.#{map-get($SassGrid, rowClassName)} {
display: grid;
grid-template-rows: auto;
grid-gap: map-get($SassGrid, gridGap);
}
@for $i from 1 through map-get($SassGrid, numberOfColumns) {
.#{map-get($SassGrid, rowClassName)}-#{$i} {
grid-template-columns: repeat($i, 1fr);
}
.#{map-get($SassGrid, colClassName)}-#{$i} {
grid-column: span $i;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment