-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path_fg_grid.scss
68 lines (55 loc) · 1.9 KB
/
_fg_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
// Global variables:
// Specify a gutter and padding amount using any CSS units you'd like
// if unitless, interpreted as pixels (e.g., $_fg_gutter: 24 !default;)
$_fg_gutter: 24px !default; // gutter between columns. Set as desired.
$_fg_padding: 12px !default; // padding for column boxes. Set as desired, can override for individual columns.
// *** Main mixin to create a per-row layout *** //
@mixin _fg($colList, $gutter: $_fg_gutter, $padding: $_fg_padding) {
// If gutter/padding is unitless, give it px units:
@if unitless($gutter) {
$gutter: $gutter * 1px;
}
@if unitless($padding) {
$padding: $padding * 1px;
}
@if type-of($colList) == number { // call _fg_grid() directly
@include _fg_grid($colList, $gutter, $padding);
} @else if type-of($colList) == list and length($colList) > 1 {
// Count how many columns there are altogether
$columnCount: 0;
@each $i in $colList {
$columnCount: $columnCount + $i;
}
@include _fg_grid($columnCount, $gutter, $padding);
@for $i from 1 through length($colList) { // set child item widths using nth:child()
$c: nth($colList, $i);
& > :nth-child(#{length($colList)}n+#{$i}) {
@include _fg_width($c/$columnCount, $gutter);
}
}
}
}
// *** Set up grid with equal width columns *** //
@mixin _fg_grid($cols: 0, $gutter: $_fg_gutter, $padding: $_fg_padding) {
box-sizing: border-box;
display: flex;
flex-wrap: wrap;
margin-left: (-1 * $gutter);
> * {
@if $padding != 0 {
padding: $padding;
}
margin-left: $gutter;
box-sizing: border-box;
}
$calc_percent: (1/$cols) * 100%;
> * { width: calc(#{$calc_percent} - #{$gutter}); }
}
// *** width override for a column *** //
@mixin _fg_width($ratio, $gutter: $_fg_gutter) {
@if unitless($gutter) {
$gutter: $gutter * 1px;
}
$calc_percent: $ratio * 100%;
width: calc(#{$calc_percent} - #{$gutter});
};