Skip to content

Instantly share code, notes, and snippets.

@Kaptard
Last active October 7, 2017 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kaptard/a47d7ed76b53be96e253fbd47298752d to your computer and use it in GitHub Desktop.
Save Kaptard/a47d7ed76b53be96e253fbd47298752d to your computer and use it in GitHub Desktop.
Minimalistic Flex Grid in SCSS
/**
* Minimalistic Flex Grid in SCSS
*/
$breakpoint-m: 75em;
$breakpoint-s: 40em;
// Rows
.row {
display: flex;
flex-direction: row;
justify-content: space-between;
@media (max-width: $breakpoint-m) {
flex-wrap: wrap;
// col-b will have 2 elements per line at this
// breakpoint, so we can remove the left/right
// margin from even/uneven to fit them to content
*[class*="col-b"] {
&:nth-child(even) {
margin-right: 0;
}
&:nth-child(odd) {
margin-left: 0;
}
}
}
@media (max-width: $breakpoint-s) {
*[class*="col-b"] {
flex-basis: 100%;
margin: 0;
}
}
}
// Columns
@mixin column($size) {
flex-grow: $size;
flex-basis: #{$size + %};
}
// .col-1, .col-2...,
// each number specifies the relative width
@for $i from 0 through 8 {
.col-#{$i},
.col-b-#{$i} {
@include column(#{$i});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment