Last active
April 20, 2020 17:22
-
-
Save pigeonfresh/958d7c32929f041ad75a684ede7a1d13 to your computer and use it in GitHub Desktop.
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
/* | |
* This mixin is used to calculate the max-width of an element within it's wrapper. | |
* | |
* The columns have a flexible width | |
* The columns are divided by a gutter | |
* The gutters have a fixed width of 40px | |
* | |
*/ | |
@mixin column($columnsWanted, $total: 12) { | |
$columnsTotal: $total; | |
$gapSize: 40; | |
$percentage: (($columnsWanted / $columnsTotal) * 100) * 1%; | |
$offset: ($gapSize / $columnsTotal) * ($columnsTotal - $columnsWanted) + px; | |
@if $columnsWanted == $columnsTotal { | |
width: 100%; | |
max-width: calc(#{$percentage} - #{$offset}); | |
} | |
} | |
/* | |
* Example | |
*/ | |
// overlap 10 of 12 columns | |
.main-wrapper { | |
@include column(10); | |
// This wrapper should overlap 5 columns of its parent overlapping 10 | |
.main-wrapper-child { | |
@include column(5, 10); | |
.main-wrapper-grand-child { | |
// should overlap 3 of the 5 | |
@include columns(3, 5); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment