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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
|
/// Makes an element's :before pseudoelement a FontAwesome icon.
/// @param {string} $content Optional content value to use.
/// @param {string} $where Optional pseudoelement to target (before or after).
@mixin icon($content: false, $where: before) {
text-decoration: none;
&:#{$where} {
@if $content {
content: $content;
}
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-transform: none !important;
}
}
/// Applies padding to an element, taking the current element-margin value into account.
/// @param {mixed} $tb Top/bottom padding.
/// @param {mixed} $lr Left/right padding.
/// @param {list} $pad Optional extra padding (in the following order top, right, bottom, left)
/// @param {bool} $important If true, adds !important.
@mixin padding($tb, $lr, $pad: (0,0,0,0), $important: null) {
@if $important {
$important: '!important';
}
$x: 0.1em;
@if unit(_size(element-margin)) == 'rem' {
$x: 0.1rem;
}
padding: ($tb + nth($pad,1)) ($lr + nth($pad,2)) max($x, $tb - _size(element-margin) + nth($pad,3)) ($lr + nth($pad,4)) #{$important};
}
/// Encodes a SVG data URL so IE doesn't choke (via codepen.io/jakob-e/pen/YXXBrp).
/// @param {string} $svg SVG data URL.
/// @return {string} Encoded SVG data URL.
@function svg-url($svg) {
$svg: str-replace($svg, '"', '\'');
$svg: str-replace($svg, '%', '%25');
$svg: str-replace($svg, '<', '%3C');
$svg: str-replace($svg, '>', '%3E');
$svg: str-replace($svg, '&', '%26');
$svg: str-replace($svg, '#', '%23');
$svg: str-replace($svg, '{', '%7B');
$svg: str-replace($svg, '}', '%7D');
$svg: str-replace($svg, ';', '%3B');
@return url("data:image/svg+xml;charset=utf8,#{$svg}");
}
/// Initializes base flexgrid classes.
/// @param {string} $vertical-align Vertical alignment of cells.
/// @param {string} $horizontal-align Horizontal alignment of cells.
@mixin flexgrid-base($vertical-align: null, $horizontal-align: null) {
// Grid.
@include vendor('display', 'flex');
@include vendor('flex-wrap', 'wrap');
// Vertical alignment.
@if ($vertical-align == top) {
@include vendor('align-items', 'flex-start');
}
@else if ($vertical-align == bottom) {
@include vendor('align-items', 'flex-end');
}
@else if ($vertical-align == center) {
@include vendor('align-items', 'center');
}
@else {
@include vendor('align-items', 'stretch');
}
// Horizontal alignment.
@if ($horizontal-align != null) {
text-align: $horizontal-align;
}
// Cells.
> * {
@include vendor('flex-shrink', '1');
@include vendor('flex-grow', '0');
}
}
/// Sets up flexgrid columns.
/// @param {integer} $columns Columns.
@mixin flexgrid-columns($columns) {
> * {
$cell-width: 100% / $columns;
width: #{$cell-width};
}
}
/// Sets up flexgrid gutters.
/// @param {integer} $columns Columns.
/// @param {number} $gutters Gutters.
@mixin flexgrid-gutters($columns, $gutters) {
// Apply padding.
> * {
$cell-width: 100% / $columns;
padding: ($gutters * 0.5);
width: $cell-width;
}
}
/// Sets up flexgrid gutters (flush).
/// @param {integer} $columns Columns.
/// @param {number} $gutters Gutters.
@mixin flexgrid-gutters-flush($columns, $gutters) {
// Apply padding.
> * {
$cell-width: 100% / $columns;
$cell-width-pad: $gutters / $columns;
padding: ($gutters * 0.5);
width: calc(#{$cell-width} + #{$cell-width-pad});
}
// Clear top/bottom gutters.
> :nth-child(-n + #{$columns}) {
padding-top: 0;
}
> :nth-last-child(-n + #{$columns}) {
padding-bottom: 0;
}
// Clear left/right gutters.
> :nth-child(#{$columns}n + 1) {
padding-left: 0;
}
> :nth-child(#{$columns}n) {
padding-right: 0;
}
// Adjust widths of leftmost and rightmost cells.
> :nth-child(#{$columns}n + 1),
> :nth-child(#{$columns}n) {
$cell-width: 100% / $columns;
$cell-width-pad: ($gutters / $columns) - ($gutters / 2);
width: calc(#{$cell-width} + #{$cell-width-pad});
}
}
/// Reset flexgrid gutters (flush only).
/// Used to override a previous set of flexgrid gutter classes.
/// @param {integer} $columns Columns.
/// @param {number} $gutters Gutters.
/// @param {integer} $prev-columns Previous columns.
@mixin flexgrid-gutters-flush-reset($columns, $gutters, $prev-columns) {
// Apply padding.
> * {
$cell-width: 100% / $prev-columns;
$cell-width-pad: $gutters / $prev-columns;
padding: ($gutters * 0.5);
width: calc(#{$cell-width} + #{$cell-width-pad});
}
// Clear top/bottom gutters.
> :nth-child(-n + #{$prev-columns}) {
padding-top: ($gutters * 0.5);
}
> :nth-last-child(-n + #{$prev-columns}) {
padding-bottom: ($gutters * 0.5);
}
// Clear left/right gutters.
> :nth-child(#{$prev-columns}n + 1) {
padding-left: ($gutters * 0.5);
}
> :nth-child(#{$prev-columns}n) {
padding-right: ($gutters * 0.5);
}
// Adjust widths of leftmost and rightmost cells.
> :nth-child(#{$prev-columns}n + 1),
> :nth-child(#{$prev-columns}n) {
$cell-width: 100% / $columns;
$cell-width-pad: $gutters / $columns;
padding: ($gutters * 0.5);
width: calc(#{$cell-width} + #{$cell-width-pad});
}
}
/// Adds debug styles to current flexgrid element.
@mixin flexgrid-debug() {
box-shadow: 0 0 0 1px red;
> * {
box-shadow: inset 0 0 0 1px blue;
position: relative;
> * {
position: relative;
box-shadow: inset 0 0 0 1px green;
}
}
}
/// Initializes the current element as a flexgrid.
/// @param {integer} $columns Columns (optional).
/// @param {number} $gutters Gutters (optional).
/// @param {bool} $flush If true, clears padding around the very edge of the grid.
@mixin flexgrid($settings: ()) {
// Settings.
// Debug.
$debug: false;
@if (map-has-key($settings, 'debug')) {
$debug: map-get($settings, 'debug');
}
// Vertical align.
$vertical-align: null;
@if (map-has-key($settings, 'vertical-align')) {
$vertical-align: map-get($settings, 'vertical-align');
}
// Horizontal align.
$horizontal-align: null;
@if (map-has-key($settings, 'horizontal-align')) {
$horizontal-align: map-get($settings, 'horizontal-align');
}
// Columns.
$columns: null;
@if (map-has-key($settings, 'columns')) {
$columns: map-get($settings, 'columns');
}
// Gutters.
$gutters: 0;
@if (map-has-key($settings, 'gutters')) {
$gutters: map-get($settings, 'gutters');
}
// Flush.
$flush: true;
@if (map-has-key($settings, 'flush')) {
$flush: map-get($settings, 'flush');
}
// Initialize base grid.
@include flexgrid-base($vertical-align, $horizontal-align);
// Debug?
@if ($debug) {
@include flexgrid-debug;
}
// Columns specified?
@if ($columns != null) {
// Initialize columns.
@include flexgrid-columns($columns);
// Gutters specified?
@if ($gutters > 0) {
// Flush gutters?
@if ($flush) {
// Initialize gutters (flush).
@include flexgrid-gutters-flush($columns, $gutters);
}
// Otherwise ...
@else {
// Initialize gutters.
@include flexgrid-gutters($columns, $gutters);
}
}
}
}
/// Resizes a previously-initialized grid.
/// @param {integer} $columns Columns.
/// @param {number} $gutters Gutters (optional).
/// @param {list} $reset A list of previously-initialized grid columns (only if $flush is true).
/// @param {bool} $flush If true, clears padding around the very edge of the grid.
@mixin flexgrid-resize($settings: ()) {
// Settings.
// Columns.
$columns: 1;
@if (map-has-key($settings, 'columns')) {
$columns: map-get($settings, 'columns');
}
// Gutters.
$gutters: 0;
@if (map-has-key($settings, 'gutters')) {
$gutters: map-get($settings, 'gutters');
}
// Previous columns.
$prev-columns: false;
@if (map-has-key($settings, 'prev-columns')) {
$prev-columns: map-get($settings, 'prev-columns');
}
// Flush.
$flush: true;
@if (map-has-key($settings, 'flush')) {
$flush: map-get($settings, 'flush');
}
// Resize columns.
@include flexgrid-columns($columns);
// Gutters specified?
@if ($gutters > 0) {
// Flush gutters?
@if ($flush) {
// Previous columns specified?
@if ($prev-columns) {
// Convert to list if it isn't one already.
@if (type-of($prev-columns) != list) {
$prev-columns: ($prev-columns);
}
// Step through list of previous columns and reset them.
@each $x in $prev-columns {
@include flexgrid-gutters-flush-reset($columns, $gutters, $x);
}
}
// Resize gutters (flush).
@include flexgrid-gutters-flush($columns, $gutters);
}
// Otherwise ...
@else {
// Resize gutters.
@include flexgrid-gutters($columns, $gutters);
}
}
}
|