Skip to content

Instantly share code, notes, and snippets.

@Abdo-Hassan
Last active November 26, 2018 19:26
Show Gist options
  • Save Abdo-Hassan/fb131f9a76fba17920ecb7438bb92eb1 to your computer and use it in GitHub Desktop.
Save Abdo-Hassan/fb131f9a76fba17920ecb7438bb92eb1 to your computer and use it in GitHub Desktop.
make grid with sass
<div class="container">
<div class="row">
<div class="col-6">6/12</div>
<div class="col-6">6/12</div>
<div class="col-4">4/12</div>
<div class="col-4">4/12</div>
<div class="col-4">4/12</div>
<div class="col-3">3/12</div>
<div class="col-3">3/12</div>
<div class="col-3">3/12</div>
<div class="col-3">3/12</div>
<div class="col-8">8/12</div>
<div class="col-4">4/12</div>
<div class="col-12">12/12</div>
</div>
</div>
// ----
// Sass (v3.5.6)
// Compass (vundefined)
// ----
* {
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}
$gridNum :12;
%grid{
background-color:#eee;
font-weight:bold;
padding:10px;
border:1px solid #aaa;
float:left;
text-align:center;
}
@for $i from 1 through 12 {
.col-#{$i} {
width:(100% / ($gridNum / $i));
@extend %grid;
}
}
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.col-1, .col-2, .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9, .col-10, .col-11, .col-12 {
background-color: #eee;
font-weight: bold;
padding: 10px;
border: 1px solid #aaa;
float: left;
text-align: center;
}
.col-1 {
width: 8.3333333333%;
}
.col-2 {
width: 16.6666666667%;
}
.col-3 {
width: 25%;
}
.col-4 {
width: 33.3333333333%;
}
.col-5 {
width: 41.6666666667%;
}
.col-6 {
width: 50%;
}
.col-7 {
width: 58.3333333333%;
}
.col-8 {
width: 66.6666666667%;
}
.col-9 {
width: 75%;
}
.col-10 {
width: 83.3333333333%;
}
.col-11 {
width: 91.6666666667%;
}
.col-12 {
width: 100%;
}
<div class="container">
<div class="row">
<div class="col-6">6/12</div>
<div class="col-6">6/12</div>
<div class="col-4">4/12</div>
<div class="col-4">4/12</div>
<div class="col-4">4/12</div>
<div class="col-3">3/12</div>
<div class="col-3">3/12</div>
<div class="col-3">3/12</div>
<div class="col-3">3/12</div>
<div class="col-8">8/12</div>
<div class="col-4">4/12</div>
<div class="col-12">12/12</div>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment