Skip to content

Instantly share code, notes, and snippets.

@space11
Created May 9, 2018 20:39
Show Gist options
  • Save space11/902f35bdd06918bc476ebdf060c74ba3 to your computer and use it in GitHub Desktop.
Save space11/902f35bdd06918bc476ebdf060c74ba3 to your computer and use it in GitHub Desktop.
The Grid System
// VERIABLES
$grid-width: 114rem;
$gutter-vertical: 8rem;
$gutter-horizontal: 6rem;
// MIXIN
@mixin clearfix {
&:after {
content: "";
display: table;
clear: both;
}
}
// GRID
.row {
max-width: $grid-width; // sass veriable
margin: 0 auto;
&:not(:last-child) {
margin-bottom: $gutter-vertical; // sass veriable
}
@include clearfix;
[class^="col-"] {
float: left;
&:not(:last-child) {
margin-right: $gutter-horizontal; // sass veriable
}
}
/* COLUMNS*/
.col-1-of-2 {
width: calc((100% - #{$gutter-horizontal}) / 2);
}
.col-1-of-3 {
width: calc((100% - 2 * #{$gutter-horizontal}) / 3);
}
.col-2-of-3 {
width: calc(
2 * ((100% - 2 * #{$gutter-horizontal}) / 3) + #{$gutter-horizontal}
);
}
.col-1-of-4 {
width: calc((100% - 3 * #{$gutter-horizontal}) / 4);
}
.col-2-of-4 {
width: calc(
(2 * (100% - 3 * #{$gutter-horizontal}) / 4) + #{$gutter-horizontal}
);
}
.col-3-of-4 {
width: calc(
(3 * (100% - 3 * #{$gutter-horizontal}) / 4) + 2 * #{$gutter-horizontal}
);
}
}
<section class="grid-test">
<div class="row">
<div class="col-1-of-2">Col 1 of 2</div>
<div class="col-1-of-2">Col 1 of 2</div>
</div>
<div class="row">
<div class="col-1-of-3">Col 1 of 3</div>
<div class="col-1-of-3">Col 1 of 3</div>
<div class="col-1-of-3">Col 1 of 3</div>
</div>
<div class="row">
<div class="col-1-of-3">Col 1 of 3</div>
<div class="col-2-of-3">Col 2 of 3</div>
</div>
<div class="row">
<div class="col-1-of-4">Col 1 of 4</div>
<div class="col-1-of-4">Col 1 of 4</div>
<div class="col-1-of-4">Col 1 of 4</div>
<div class="col-1-of-4">Col 1 of 4</div>
</div>
<div class="row">
<div class="col-1-of-4">Col 1 of 4</div>
<div class="col-1-of-4">Col 1 of 4</div>
<div class="col-2-of-4">Col 2 of 4</div>
</div>
<div class="row">
<div class="col-1-of-4">Col 1 of 4</div>
<div class="col-3-of-4">Col 3 of 4</div>
</div>
</section>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment