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
|
//
// Mixins for the Zen Grids system.
//
// Specify the number of columns in the grid.
$zen-column-count: 1 !default;
// Specify the width of the gutters; half of the gutter will be placed on each
// side of a grid column.
$zen-gutter-width: 20px !default;
// You can generate more efficient CSS if you manually apply the
// zen-grid-item-base mixin to all grid items from within a single ruleset.
$zen-auto-include-item-base: true !default;
$zen-auto-include-flow-item-base: true !default;
// Specify the width of the entire grid. Defaults to 100% for a fluid responsive
// design, but you can change this to a pixel value if you need a fixed grid.
$zen-grid-width: 100% !default;
// The box-sizing polyfill for IE6/7 requires an absolute path to the
// boxsizing.htc file. See https://github.com/Schepp/box-sizing-polyfill
$box-sizing-polyfill-path: "" !default;
// Specify the CSS3 box-sizing method. The default, "border-box", is compatible
// with all modern browsers, including IE 8 and later. Use "content-box" for
// wider compatibility (Note: you'll also need to set $legacy-support-for-ie7
// and $legacy-support-for-ie6 to true.)
$zen-box-sizing: border-box !default;
// Turn off IE6/7 support since we're defaulting to box-sizing: border-box.
$legacy-support-for-ie7: false !default;
$legacy-support-for-ie6: false !default;
// Specify the default floating direction for zen's mixins.
$zen-float-direction: left !default;
// This is a helper variable for RTL layouts.
$zen-reverse-all-floats: false !default;
//
// Apply this to the grid container element.
//
@mixin zen-grid-container () {
@if ($legacy-support-for-ie6 or $legacy-support-for-ie7) {
*position: relative; // @TODO: This is a pre-IE8 line of code; don't remember why its needed.
}
// We use the "micro clearfix", instead of Compass' clearfix or pie-clearfix.
&:before,
&:after {
content: "";
display: table;
}
&:after {
clear: both;
}
@if ($legacy-support-for-ie6 or $legacy-support-for-ie7) {
*zoom: 1;
}
}
//
// Apply this to any grid item that is also a grid container element for a
// nested grid. It must be applied after the zen-grid-item() mixin.
//
@mixin zen-nested-container () {
padding: {
left: 0;
right: 0;
}
}
//
// Apply this to each grid item. Set the $column-span to the number of columns
// that the grid item spans. And set the $column-position to the column number
// the grid item starts on.
//
// For grid items that are floated right, the $column-position is counted
// from the right instead of from the left.
//
@mixin zen-grid-item (
$column-span,
$column-position,
$float-direction: $zen-float-direction,
$column-count: $zen-column-count,
$gutter-width: $zen-gutter-width,
$grid-width: $zen-grid-width,
$box-sizing: $zen-box-sizing,
$reverse-all-floats: $zen-reverse-all-floats,
$auto-include-item-base: $zen-auto-include-item-base
) {
// Calculate the unit width.
$unit-width: zen-unit-width($column-count, $grid-width);
// Determine the float direction and its reverse.
$dir: $float-direction;
@if $reverse-all-floats {
$dir: zen-direction-flip($dir);
}
$rev: zen-direction-flip($dir);
float: $dir;
$width: $column-span * $unit-width;
@if $box-sizing == content-box {
@if not comparable($width, $gutter-width) {
$units-gutter: unit($gutter-width);
$units-grid: unit($grid-width);
@warn "The layout cannot be calculated correctly; when using box-sizing: content-box, the units of the gutter (#{$units-gutter} did not match the units of the grid width (#{$units-grid}).";
}
$width: $width - $gutter-width;
}
width: $width;
margin: {
#{$dir}: ($column-position - 1) * $unit-width;
#{$rev}: (1 - $column-position - $column-span) * $unit-width;
}
// Auto-apply the unit base mixin.
@if $auto-include-item-base {
@include zen-grid-item-base($gutter-width, $box-sizing);
}
}
//
// Applies a standard set of properites to all grid items in the layout.
//
// See the note about the $zen-auto-include-item-base and
// $zen-auto-include-flow-item-base variables for when to use this mixin.
//
// The mixin has the following optional parameters, but its better to use the
// $zen-gutter-width and $zen-box-sizing variables instead:
// - $gutter-width: Half of this value is applied as padding to the left and
// right sides of the item.
// - $box-sizing: The type of CSS3 box model each box should use. Can be set to
// content-box or border-box. Defaults to content-box, but border-box is way
// cooler. IE 6 and 7 don't support border-box.
@mixin zen-grid-item-base (
$gutter-width: $zen-gutter-width,
$box-sizing: $zen-box-sizing,
$flow-direction: $zen-float-direction,
$reverse-all-flows: $zen-reverse-all-floats
) {
$dir: $flow-direction;
@if $reverse-all-flows {
$dir: zen-direction-flip($dir);
}
padding: {
left: zen-half-gutter($gutter-width, left, $dir);
right: zen-half-gutter($gutter-width, right, $dir);
}
// Specify the border-box properties.
@if $box-sizing == border-box {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
-ms-box-sizing: border-box;
box-sizing: border-box;
}
// Prevent borders since they'll break the layout with content-box.
@if $box-sizing == content-box {
border: 0 !important;
}
// Prevent overflowing content from being hidden beneath other grid items.
word-wrap: break-word; // A very nice CSS3 property.
@if ($legacy-support-for-ie6 or $legacy-support-for-ie7) {
@if $box-sizing == border-box and $box-sizing-polyfill-path == "" {
@warn "IE legacy support is on, but $box-sizing is set to #{$box-sizing} and the $box-sizing-polyfill-path is empty.";
}
@if $box-sizing-polyfill-path != "" {
*behavior: url($box-sizing-polyfill-path);
}
@if $legacy-support-for-ie6 {
_display: inline; // Display inline or double your floated margin! [1]
_overflow: hidden; // Prevent overflowing content from breaking the layout.
_overflow-y: visible; // In IE6, overflow visible is broken [2]
// 1. http://www.positioniseverything.net/explorer/doubled-margin.html
// 2. http://www.howtocreate.co.uk/wrongWithIE/?chapter=overflow%3Avisible%3B
}
}
}
//
// Apply this to content boxes that need to be cleared below other content boxes.
//
@mixin zen-clear (
$float-direction: $zen-float-direction,
$reverse-all-floats: $zen-reverse-all-floats
) {
// Determine the float direction.
$dir: $float-direction;
@if $reverse-all-floats {
$dir: zen-direction-flip($dir);
}
clear: $dir;
}
//
// Apply this to flow items that need to be floated.
//
@mixin zen-float (
$float-direction: $zen-float-direction,
$reverse-all-floats: $zen-reverse-all-floats
) {
// Determine the float direction.
$dir: $float-direction;
@if $reverse-all-floats {
$dir: zen-direction-flip($dir);
}
float: $dir;
}
//
// Apply this to an HTML item that is in the normal flow of a document to help
// align it to the grid. Set the $column-span to the number of columns that the
// HTML element should span. For responsive layouts with a percentage-based grid
// width, set the $parent-column-count to the number of columns that the parent
// element spans; fixed-unit layouts using px, em, etc. do not need to specify
// this.
//
// Unlike the zen-grid-item() mixin, this mixin does not float the HTML item; it
// also does not have a half-gutter on each side. By default, it has no gutter
// in the "alpha position" (the left side) and a full gutter in the "omega
// position" (the right side.) You can turn on or off the alpha and omega
// gutters by setting the $alpha-gutter and $omega-gutter parameters to true or
// false.
//
// Note: when the $flow-direction is set to right (for RTL languages), the alpha
// position is on the right and the omega position is on the left.
//
@mixin zen-grid-flow-item (
$column-span,
$parent-column-count: false,
$alpha-gutter: false,
$omega-gutter: true,
$flow-direction: $zen-float-direction,
$column-count: $zen-column-count,
$gutter-width: $zen-gutter-width,
$grid-width: $zen-grid-width,
$box-sizing: $zen-box-sizing,
$reverse-all-flows: $zen-reverse-all-floats,
$auto-include-flow-item-base: $zen-auto-include-flow-item-base
) {
$columns: $column-count;
@if unit($grid-width) == "%" {
@if $parent-column-count == false {
@warn "For responsive layouts with a percentage-based grid width, you must set the $column-count to the number of columns that the parent element spans.";
}
@else {
$columns: $parent-column-count;
}
}
$dir: $flow-direction;
@if $reverse-all-flows {
$dir: zen-direction-flip($dir);
}
$rev: zen-direction-flip($dir);
// Calculate the item's width.
$width: zen-grid-item-width($column-span, $columns, $grid-width);
@if $box-sizing == content-box {
@if not comparable($width, $gutter-width) {
$units-gutter: unit($gutter-width);
$units-grid: unit($grid-width);
@warn "The layout cannot be calculated correctly; when using box-sizing: content-box, the units of the gutter (#{$units-gutter} did not match the units of the grid width (#{$units-grid}).";
}
$width: $width - $gutter-width;
}
width: $width;
// Auto-apply the unit base mixin.
@if $auto-include-flow-item-base {
@include zen-grid-item-base($gutter-width, $box-sizing);
}
// Ensure the HTML item either has a full gutter or no gutter on each side.
padding-#{$dir}: 0;
@if $alpha-gutter {
margin-#{$dir}: $gutter-width;
}
$offset: ($columns - $column-span) * $gutter-width / $columns;
padding-#{$rev}: $offset;
@if $omega-gutter {
margin-#{$rev}: $gutter-width - $offset;
}
@else {
margin-#{$rev}: -($offset);
}
}
//
// Helper functions for the Zen mixins.
//
// Returns a half gutter width.
@function zen-half-gutter(
$gutter-width: $zen-gutter-width,
$gutter-side: $zen-float-direction,
$flow-direction: $zen-float-direction
) {
$half-gutter: $gutter-width / 2;
// Special handling in case gutter has an odd number of pixels.
@if unit($gutter-width) == "px" {
@if $gutter-side == $flow-direction {
@return floor($half-gutter);
}
@else {
@return ceil($half-gutter);
}
}
@return $half-gutter;
}
// Calculates the unit width of a column.
@function zen-unit-width (
$column-count: $zen-column-count,
$grid-width: $zen-grid-width
) {
$unit-width: $grid-width / $column-count;
@if unit($unit-width) == "px" and floor($unit-width) != ceil($unit-width) {
@warn "You may experience rounding errors as the grid width, #{$grid-width}, does not divide evenly into #{$column-count} columns.";
}
@return $unit-width;
}
// Calculates the width of a grid item that spans the specified number of columns.
@function zen-grid-item-width (
$column-span,
$column-count: $zen-column-count,
$grid-width: $zen-grid-width
) {
@return $column-span * zen-unit-width($column-count, $grid-width);
}
// Returns the opposite direction, given "left" or "right".
@function zen-direction-flip($dir) {
@if $dir == left {
@return right;
}
@else if $dir == right {
@return left;
}
@else if $dir == none or $dir == both {
@return $dir;
}
@warn "Invalid direction passed to zen-direction-flip().";
@return both;
}
|