-
Notifications
You must be signed in to change notification settings - Fork 0
/
_grid.scss
63 lines (51 loc) · 1.5 KB
/
_grid.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
@use "sass:math";
/// Grid
///
/// @param {Map} $args - Grid settings
@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: border-box;
clear: both;
margin-bottom: map-get($settings, 'margin');
width: 100%;
@each $breakpoint, $columns in map-get($settings, 'breakpoints') {
@media(min-width: $breakpoint) {
$total-spacing: (map-get($settings, 'margin') * ($columns - 1));
clear: none;
float: left;
margin-right: map-get($settings, 'margin');
width: calc(math.div(100%, $columns) - math.div($total-spacing, $columns));
$current-breakpoint-index: index(map-keys(map-get($settings, 'breakpoints')), $breakpoint);
@if $current-breakpoint-index > 1 {
$previous-columns: nth(map-values(map-get($settings, 'breakpoints')), $current-breakpoint-index - 1);
&:nth-child(#{($previous-columns)}n) {
margin-right: map-get($settings, 'margin');
}
&:nth-child(#{($previous-columns)}n+1) {
clear: none;
}
}
&:nth-child(#{$columns}n) {
margin-right: 0;
}
&:nth-child(#{$columns}n+1) {
clear: left;
}
}
}
}
}