Last active
April 4, 2017 12:07
-
-
Save johndevman/6ea41020fdafe888cd3f901a9a1dcfd9 to your computer and use it in GitHub Desktop.
BEM Sass grid component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$grid-columns: 12 !default; | |
$grid-gutter: 10px !default; | |
$grid-gutter-half: $grid-gutter / 2; | |
.grid { | |
/*@include breakpoint("tablet") { | |
flex-direction: row; | |
}*/ | |
display: flex; | |
flex-direction: column; | |
padding: 0 $grid-gutter-half; | |
&--is-multiline { | |
flex-wrap: wrap; | |
} | |
} | |
.grid__column { | |
flex: 1; | |
margin: 0 $grid-gutter-half; | |
@for $i from 1 through $grid-columns { | |
$width: ($i / $grid-columns) * 100%; | |
&--is-#{$i} { | |
flex: initial; | |
width: calc(#{$width} - #{$grid-gutter}); | |
} | |
} | |
&--is-narrow { | |
flex: initial; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Each columns shares the same width --> | |
<div class="grid"> | |
<div class="grid__column">Each grid column has an equal width.</div> | |
<div class="grid__column">Each grid column has an equal width.</div> | |
</div> | |
<!-- Multiline modifier wraps column onto a new row --> | |
<div class="grid grid--is-multiline"> | |
<!-- | |
We can also add a grid__column--is-{size} to change a columns size | |
where {size} range from 1 through $grid-columns | |
--> | |
<div class="grid__column grid__column--is-6">50%</div> | |
<div class="grid__column grid__column--is-6">50%</div> | |
<div class="grid__column grid__column--is-6">50%</div> | |
</div> | |
<div class="grid"> | |
<div class="grid__column"> | |
Hello | |
</div> | |
<!-- .grid__column--is-narrow modifier takes up that much size it needs --> | |
<div class="grid__column grid__column--is-narrow"> | |
Hello, hello, hello | |
</div> | |
<div class="grid__column"> | |
Hello | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment