UNPKG

6.68 kBSCSSView Raw
1// Foundation for Sites by ZURB
2// foundation.zurb.com
3// Licensed under MIT Open Source
4
5////
6/// @group flex-grid
7////
8
9/// Creates a container for a flex grid row.
10///
11/// @param {Keyword|List} $behavior [null]
12/// Modifications to the default grid styles. `nest` indicates the row will be placed inside another row. `collapse` indicates that the columns inside this row will not have padding. `nest collapse` combines both behaviors.
13/// @param {Keyword|Number} $size [$grid-row-width] Maximum size of the row. Set to `expand` to make the row taking the full width.
14/// @param {Number} $columns [null] - Number of columns to use for this row. If set to `null` (the default), the global column count will be used.
15/// @param {Boolean} $base [true] - Set to `false` to prevent basic styles from being output. Useful if you're calling this mixin on the same element twice, as it prevents duplicate CSS output.
16/// @param {Number|Map} $gutters [$grid-column-gutter] - Gutter map or single value to use when inverting margins, in case the row is nested. Responsive gutter settings by default.
17@mixin flex-grid-row(
18 $behavior: null,
19 $size: $grid-row-width,
20 $columns: null,
21 $base: true,
22 $wrap: true,
23 $gutters: $grid-column-gutter
24) {
25 $margin: auto;
26 $wrap: if($wrap, wrap, nowrap);
27
28 @if index($behavior, nest) != null {
29 @include grid-row-nest($gutters);
30
31 @if index($behavior, collapse) != null {
32 margin-right: 0;
33 margin-left: 0;
34 }
35 }
36 @else {
37 @include grid-row-size($size);
38 margin-right: auto;
39 margin-left: auto;
40 }
41
42 @if $base {
43 display: flex;
44 flex-flow: row $wrap;
45 }
46
47 @if $columns != null {
48 @include grid-context($columns, $base) {
49 @content;
50 }
51 }
52}
53
54/// Calculates the `flex` property for a flex grid column. It accepts all of the same values as the basic `grid-column()` function, along with two extras:
55/// - `expand` (the default) will make the column expand to fill space.
56/// - `shrink` will make the column contract, so it only takes up the horizontal space it needs.
57///
58/// @param {Mixed} $columns [expand] - Width of the column.
59@function flex-grid-column($columns: expand) {
60 $flex: 1 1 0px; // sass-lint:disable-line zero-unit
61
62 @if $columns == shrink {
63 $flex: 0 0 auto;
64 }
65 @else if $columns != expand {
66 $flex: 0 0 grid-column($columns);
67 }
68
69 @return $flex;
70}
71
72/// Creates a column for a flex grid. By default, the column will stretch to the full width of its container, but this can be overridden with sizing classes, or by using the `unstack` class on the parent flex row.
73///
74/// @param {Mixed} $columns [expand] - Width of the column. Refer to the `flex-grid-column()` function to see possible values.
75/// @param {Number|Map} $gutters [$grid-column-gutter] - Map or single value for gutters width. See the `grid-column-gutter` mixin.
76@mixin flex-grid-column(
77 $columns: expand,
78 $gutters: $grid-column-gutter
79) {
80 // Base properties
81 @include flex-grid-size($columns);
82
83 // Gutters
84 @include grid-column-gutter($gutters: $gutters);
85
86 // fixes recent Chrome version not limiting child width
87 // https://stackoverflow.com/questions/34934586/white-space-nowrap-and-flexbox-did-not-work-in-chrome
88 @if $columns == expand {
89 min-width: 0;
90 }
91}
92
93/// Creates a block grid for a flex grid row.
94///
95/// @param {Number} $n - Number of columns to display on each row.
96/// @param {String} $selector - Selector to use to target columns within the row.
97@mixin flex-grid-layout(
98 $n,
99 $selector: '.column'
100) {
101 flex-wrap: wrap;
102
103 > #{$selector} {
104 $pct: percentage(1/$n);
105
106 flex: 0 0 $pct;
107 max-width: $pct;
108 }
109}
110
111/// Changes the width flex grid column.
112/// @param {Mixed} $columns [expand] - Width of the column. Refer to the `flex-grid-column()` function to see possible values.
113@mixin flex-grid-size($columns: null) {
114 $columns: $columns or expand;
115
116 flex: flex-grid-column($columns);
117
118 // max-width fixes IE 10/11 not respecting the flex-basis property
119 @if $columns != expand and $columns != shrink {
120 max-width: grid-column($columns);
121 }
122}
123
124
125@mixin foundation-flex-grid {
126 // Row
127 .row {
128 @include flex-grid-row;
129
130 // Nesting behavior
131 & .row {
132 @include flex-grid-row(nest, $base: false);
133
134 &.collapse {
135 margin-right: 0;
136 margin-left: 0;
137 }
138 }
139
140 // Expanded row
141 &.expanded {
142 @include grid-row-size(expand);
143
144 .row {
145 margin-right: auto;
146 margin-left: auto;
147 }
148 }
149
150 &:not(.expanded) .row {
151 @include grid-row-size(expand);
152 }
153
154 &.collapse {
155 > .column {
156 @include grid-col-collapse;
157 }
158 }
159
160 // Undo negative margins
161 // From collapsed child
162 &.is-collapse-child,
163 &.collapse > .column > .row {
164 margin-right: 0;
165 margin-left: 0;
166 }
167 }
168
169 // Column
170 .column {
171 @include flex-grid-column;
172 }
173
174 // Column row
175 // The double .row class is needed to bump up the specificity
176 .column.row.row {
177 float: none;
178 display: block;
179 }
180
181 // To properly nest a column row, padding and margin is removed
182 .row .column.row.row {
183 margin-right: 0;
184 margin-left: 0;
185 padding-right: 0;
186 padding-left: 0;
187 }
188
189 @include -zf-each-breakpoint {
190 @for $i from 1 through $grid-column-count {
191 // Sizing (percentage)
192 .#{$-zf-size}-#{$i} {
193 flex: flex-grid-column($i);
194 max-width: grid-column($i);
195 }
196
197 // Offsets
198 $o: $i - 1;
199
200 .#{$-zf-size}-offset-#{$o} {
201 @include grid-column-offset($o);
202 }
203 }
204
205 // Block grid
206 @for $i from 1 through $block-grid-max {
207 .#{$-zf-size}-up-#{$i} {
208 @include flex-grid-layout($i);
209 }
210 }
211
212 @if $-zf-size != $-zf-zero-breakpoint {
213 // Sizing (expand)
214 @include breakpoint($-zf-size) {
215 .#{$-zf-size}-expand {
216 flex: flex-grid-column();
217 }
218 }
219
220 // Auto-stacking/unstacking
221 @at-root (without: media) {
222 .row.#{$-zf-size}-unstack {
223 > .column {
224 flex: flex-grid-column(100%);
225
226 @include breakpoint($-zf-size) {
227 flex: flex-grid-column();
228 }
229 }
230 }
231 }
232 }
233
234 // Responsive collapsing
235 .#{$-zf-size}-collapse {
236 > .column { @include grid-col-collapse; }
237 }
238
239 .#{$-zf-size}-uncollapse {
240 > .column { @include grid-col-gutter($-zf-size); }
241 }
242 }
243
244 // Sizing (shrink)
245 .shrink {
246 flex: flex-grid-column(shrink);
247 max-width: 100%;
248 }
249
250 // Block grid columns
251 .column-block {
252 @include grid-column-margin;
253 }
254
255 .columns {
256 @extend .column; // sass-lint:disable-line placeholder-in-extend
257
258 }
259}