Skip to content

Instantly share code, notes, and snippets.

@Twikito
Last active July 25, 2018 09:47
Show Gist options
  • Save Twikito/27a252f08d70dbba8544446f384a13ce to your computer and use it in GitHub Desktop.
Save Twikito/27a252f08d70dbba8544446f384a13ce to your computer and use it in GitHub Desktop.
Ultimate grid system
$global-gutters: 2rem;
$wrapper-width : 96rem;
[class*=' grid-'],
[class^='grid-'] {
--grid-item-min-width: 1fr;
display: grid;
grid-template-columns: repeat( auto-fill, minmax( var(--grid-item-min-width), 1fr ) );
grid-gap: $global-gutters $global-gutters; grid-auto-flow: row dense; justify-items: stretch; align-items: stretch;
// To deal with overflows
& > * {
min-width: 0;
}
}
// This let you create a grid in any context
@mixin grid($from, $to, $width, $scope: '') {
@for $i from $from through $to {
$a: ($width / $i) - $global-gutters;
@include media('>#{$a}') {
#{$scope} .grid-#{$i} {
--grid-item-min-width: #{$a};
}
}
}
}
@include grid(1, 4, $wrapper-width, '.wrapper');
.grid-item-full {
grid-column: 1 / -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment