-
Notifications
You must be signed in to change notification settings - Fork 0
/
_grid.scss
112 lines (99 loc) · 2.18 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
@use "sass:math";
$breakpoints: (
"sm": 768,
"md": 1024,
"lg": 1366
) !default;
/// A simple grid generator
/// @param {number} $columns The number of available slots in a row
/// @param {number} $gap The grid gap
/// @param {bool} $flex If true, the implementation will be based on flexbox instead of grid
///
@mixin grid($columns: 12, $gap: 1rem, $flex: false) {
.row {
@if $flex {
display: flex;
width: calc(100% + #{$gap});
left: math.div($gap, -2);
} @else {
display: grid;
grid-template-columns: repeat($columns, minmax(0, 1fr));
grid-gap: $gap;
}
position: relative;
.row + & {
margin-top: $gap;
}
}
.row--center {
align-items: center;
}
.row--start {
@if flex {
align-items: flex-start;
} @else {
align-items: start;
}
}
.row--end {
@if flex {
align-items: flex-end;
} @else {
align-items: end;
}
}
.col {
@if $flex {
flex-basis: 100%;
padding: 0 math.div($gap, 2);
} @else {
grid-column: span $columns;
grid-row-start: 1;
}
position: relative;
}
@for $i from 1 through $columns {
.col.span-#{$i} {
@if $flex {
flex-basis: math.div($i, $columns) * 100%
} @else {
grid-column: span $i / span $i;
}
}
}
@each $key, $size in $breakpoints {
@media screen and (min-width: #{$size}px) {
@for $i from 1 through $columns {
.col.#{$key}\:span-#{$i} {
@if $flex {
flex-basis: math.div($i, $columns) * 100%
} @else {
grid-column: span $i / span $i;
}
}
}
}
}
@for $i from 1 through $columns {
.col.start-#{$i} {
@if $flex {
margin-left: math.div(($i - 1), $columns) * 100%;
} @else {
grid-column-start: $i;
}
}
}
@each $key, $size in $breakpoints {
@media screen and (min-width: #{$size}px) {
@for $i from 1 through $columns {
.col.#{$key}\:start-#{$i} {
@if $flex {
margin-left: math.div(($i - 1), $columns) * 100%;
} @else {
grid-column-start: $i;
}
}
}
}
}
}