Skip to content

Commit

Permalink
Grid
Browse files Browse the repository at this point in the history
  • Loading branch information
haroldangenent committed Jan 21, 2016
1 parent af4655e commit af0de1e
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions _grid.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/// Grid
@mixin grid($args: ()) {
$settings: map-merge((
'breakpoints': (
421px: 2,
641px: 3,
981px: 4
),
'item': null,
'margin': 20px,
), $args);

@if not map-get($settings, 'item') {
@error '`item` should be set in grid() arguments.';
}

box-sizing: border-box;
float: left;

#{map-get($settings, 'item')} {
box-sizing: inherit;
clear: both;
margin-bottom: map-get($settings, 'margin');
width: 100%;

@each $breakpoint, $columns in map-get($settings, 'breakpoints') {
@media(min-width: $breakpoint) {
$totalSpacing: (map-get($settings, 'margin') * ($columns - 1));

clear: none;
float: left;
margin-right: map-get($settings, 'margin');
width: calc((100% / #{$columns}) - #{($totalSpacing / $columns)});

$currentBreakpointIndex: index(map-keys(map-get($settings, 'breakpoints')), $breakpoint);

@if $currentBreakpointIndex > 1 {
$previousColumns: nth(map-values(map-get($settings, 'breakpoints')), $currentBreakpointIndex - 1);

&:nth-child(#{($previousColumns)}n) {
margin-right: map-get($settings, 'margin');
}
}

&:nth-child(#{$columns}n) {
margin-right: 0;
}
}
}
}
}

0 comments on commit af0de1e

Please sign in to comment.