mixins.less 17.3 KB
Newer Older
1
2
3
//
// Mixins
// --------------------------------------------------
4

5

6
7
// Utilities
// -------------------------
8
9

// Clearfix
10
11
12
13
14
15
16
17
18
19
// Source: http://nicolasgallagher.com/micro-clearfix-hack/
//
// For modern browsers
// 1. The space content is one way to avoid an Opera bug when the
//    contenteditable attribute is included anywhere else in the document.
//    Otherwise it causes space to appear at the top and bottom of elements
//    that are clearfixed.
// 2. The use of `table` rather than `block` is only necessary if using
//    `:before` to contain the top-margins of child elements.
.clear_float() {
20
  &:before,
21
  &:after {
22
23
    content: " "; /* 1 */
    display: table; /* 2 */
24
25
  }
  &:after {
26
    clear: both;
27
  }
28
29
}

Mark Otto's avatar
Mark Otto committed
30
31
32
// Webkit-style focus
.tab-focus() {
  // Default
33
  outline: thin dotted #333;
Mark Otto's avatar
Mark Otto committed
34
35
36
37
38
  // Webkit
  outline: 5px auto -webkit-focus-ring-color;
  outline-offset: -2px;
}

39
// Center-align a block level element
40
.center-block() {
41
  display: block;
42
43
  margin-left: auto;
  margin-right: auto;
44
45
46
}

// Sizing shortcuts
47
.size(@width, @height) {
48
  width: @width;
49
  height: @height;
50
}
51
.square(@size) {
52
  .size(@size, @size);
53
54
}

55
// Placeholder text
Mark Otto's avatar
Mark Otto committed
56
.placeholder(@color: @input-color-placeholder) {
57
58
59
60
  &:-moz-placeholder            { color: @color; } // Firefox 4-18
  &::-moz-placeholder           { color: @color; } // Firefox 19+
  &:-ms-input-placeholder       { color: @color; } // Internet Explorer 10+
  &::-webkit-input-placeholder  { color: @color; } // Safari and Chrome
61
62
}

Mark Otto's avatar
Mark Otto committed
63
64
65
66
67
68
69
70
// Text overflow
// Requires inline-block or block for proper styling
.text-overflow() {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

71
72
// CSS image replacement
// Source: https://github.com/h5bp/html5-boilerplate/commit/aa0396eae757
73
.hide-text() {
74
75
  font: 0/0 a;
  color: transparent;
76
  text-shadow: none;
77
  background-color: transparent;
78
  border: 0;
79
}
80

81

82

83
84
85
// CSS3 PROPERTIES
// --------------------------------------------------

86
// Single side border-radius
87
.border-top-radius(@radius) {
88
89
  border-top-right-radius: @radius;
   border-top-left-radius: @radius;
90
91
}
.border-right-radius(@radius) {
92
93
  border-bottom-right-radius: @radius;
     border-top-right-radius: @radius;
Mark Otto's avatar
Mark Otto committed
94
95
}
.border-bottom-radius(@radius) {
96
97
  border-bottom-right-radius: @radius;
   border-bottom-left-radius: @radius;
Mark Otto's avatar
Mark Otto committed
98
99
}
.border-left-radius(@radius) {
100
101
  border-bottom-left-radius: @radius;
     border-top-left-radius: @radius;
102
103
}

104
// Drop shadows
Mark Otto's avatar
Mark Otto committed
105
.box-shadow(@shadow) {
106
  -webkit-box-shadow: @shadow; // iOS <4.3 & Android <4.1
107
          box-shadow: @shadow;
108
109
110
}

// Transitions
Mark Otto's avatar
Mark Otto committed
111
112
113
114
115
.transition(@transition) {
  -webkit-transition: @transition;
     -moz-transition: @transition;
       -o-transition: @transition;
          transition: @transition;
116
}
Tunghsiao Liu's avatar
Tunghsiao Liu committed
117
118
119
120
121
122
.transition-delay(@transition-delay) {
  -webkit-transition-delay: @transition-delay;
     -moz-transition-delay: @transition-delay;
       -o-transition-delay: @transition-delay;
          transition-delay: @transition-delay;
}
Tunghsiao Liu's avatar
Tunghsiao Liu committed
123
124
125
126
127
128
.transition-duration(@transition-duration) {
  -webkit-transition-duration: @transition-duration;
     -moz-transition-duration: @transition-duration;
       -o-transition-duration: @transition-duration;
          transition-duration: @transition-duration;
}
129

Mark Otto's avatar
Mark Otto committed
130
// Transformations
131
.rotate(@degrees) {
132
133
  -webkit-transform: rotate(@degrees);
     -moz-transform: rotate(@degrees);
Mark Otto's avatar
Mark Otto committed
134
135
      -ms-transform: rotate(@degrees);
       -o-transform: rotate(@degrees);
136
137
          transform: rotate(@degrees);
}
138
139
140
141
142
143
.scale(@ratio) {
  -webkit-transform: scale(@ratio);
     -moz-transform: scale(@ratio);
      -ms-transform: scale(@ratio);
       -o-transform: scale(@ratio);
          transform: scale(@ratio);
144
}
145
.translate(@x, @y) {
Mark Otto's avatar
Mark Otto committed
146
147
148
149
150
151
  -webkit-transform: translate(@x, @y);
     -moz-transform: translate(@x, @y);
      -ms-transform: translate(@x, @y);
       -o-transform: translate(@x, @y);
          transform: translate(@x, @y);
}
152
.skew(@x, @y) {
Mark Otto's avatar
Mark Otto committed
153
154
  -webkit-transform: skew(@x, @y);
     -moz-transform: skew(@x, @y);
155
      -ms-transform: skewX(@x) skewY(@y); // See https://github.com/twitter/bootstrap/issues/4885
Mark Otto's avatar
Mark Otto committed
156
157
       -o-transform: skew(@x, @y);
          transform: skew(@x, @y);
158
  -webkit-backface-visibility: hidden; // See https://github.com/twitter/bootstrap/issues/5319
Mark Otto's avatar
Mark Otto committed
159
}
160
.translate3d(@x, @y, @z) {
161
162
163
164
  -webkit-transform: translate3d(@x, @y, @z);
     -moz-transform: translate3d(@x, @y, @z);
       -o-transform: translate3d(@x, @y, @z);
          transform: translate3d(@x, @y, @z);
165
}
166

167
168
169
170
// Backface visibility
// Prevent browsers from flickering when using CSS 3D transforms.
// Default value is `visible`, but can be changed to `hidden
// See git pull https://github.com/dannykeane/bootstrap.git backface-visibility for examples
171
.backface-visibility(@visibility){
172
	-webkit-backface-visibility: @visibility;
173
174
	   -moz-backface-visibility: @visibility;
	        backface-visibility: @visibility;
175
176
}

177
// Background clipping
Mark Otto's avatar
Mark Otto committed
178
179
180
181
.background-clip(@clip) {
  -webkit-background-clip: @clip;
     -moz-background-clip: @clip;
          background-clip: @clip;
182
183
}

184
// Background sizing
185
.background-size(@size) {
Mark Otto's avatar
Mark Otto committed
186
187
188
189
  -webkit-background-size: @size;
     -moz-background-size: @size;
       -o-background-size: @size;
          background-size: @size;
190
191
}

192
193
194
195
196
197
198
// Box sizing
.box-sizing(@boxmodel) {
  -webkit-box-sizing: @boxmodel;
     -moz-box-sizing: @boxmodel;
          box-sizing: @boxmodel;
}

199
200
201
202
203
// User select
// For selecting text on the page
.user-select(@select) {
  -webkit-user-select: @select;
     -moz-user-select: @select;
Han Lin Yap's avatar
Han Lin Yap committed
204
      -ms-user-select: @select;
205
206
207
208
       -o-user-select: @select;
          user-select: @select;
}

209
// Resize anything
210
.resizable(@direction) {
211
212
213
214
  resize: @direction; // Options: horizontal, vertical, both
  overflow: auto; // Safari fix
}

215
// CSS3 Content Columns
216
217
218
219
220
221
222
.content-columns(@column-count, @column-gap: @grid-gutter-width) {
  -webkit-column-count: @column-count;
     -moz-column-count: @column-count;
          column-count: @column-count;
  -webkit-column-gap: @column-gap;
     -moz-column-gap: @column-gap;
          column-gap: @column-gap;
223
224
}

Synchro's avatar
Synchro committed
225
226
// Optional hyphenation
.hyphens(@mode: auto) {
Mark Otto's avatar
Mark Otto committed
227
  word-wrap: break-word;
Synchro's avatar
Synchro committed
228
229
230
  -webkit-hyphens: @mode;
     -moz-hyphens: @mode;
      -ms-hyphens: @mode;
Synchro's avatar
Synchro committed
231
       -o-hyphens: @mode;
Synchro's avatar
Synchro committed
232
233
234
          hyphens: @mode;
}

235
// Opacity
236
.opacity(@opacity) {
237
238
  opacity: @opacity;
  // IE8 filter
239
  @opacity-ie: (@opacity * 100);
240
  filter: ~"alpha(opacity=@{opacity-ie})";
241
242
243
244
245
246
247
}



// BACKGROUNDS
// --------------------------------------------------

248
249
// Gradients
#gradient {
250
  .horizontal(@startColor: #555, @endColor: #333) {
251
252
    background-color: @endColor;
    background-image: -moz-linear-gradient(left, @startColor, @endColor); // FF 3.6+
253
    background-image: -webkit-gradient(linear, 0 0, 100% 0, from(@startColor), to(@endColor)); // Safari 4+, Chrome 2+
254
255
    background-image: -webkit-linear-gradient(left, @startColor, @endColor); // Safari 5.1+, Chrome 10+
    background-image: -o-linear-gradient(left, @startColor, @endColor); // Opera 11.10
256
    background-image: linear-gradient(to right, @startColor, @endColor); // Standard, IE10
257
    background-repeat: repeat-x;
258
    filter: e(%("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=1)",argb(@startColor),argb(@endColor))); // IE9 and down
259
  }
260
  .vertical(@startColor: #555, @endColor: #333) {
261
    background-color: @endColor;
Mark Otto's avatar
Mark Otto committed
262
    background-image: -moz-linear-gradient(top, @startColor, @endColor); // FF 3.6+
263
    background-image: -webkit-gradient(linear, 0 0, 0 100%, from(@startColor), to(@endColor)); // Safari 4+, Chrome 2+
Mark Otto's avatar
Mark Otto committed
264
265
    background-image: -webkit-linear-gradient(top, @startColor, @endColor); // Safari 5.1+, Chrome 10+
    background-image: -o-linear-gradient(top, @startColor, @endColor); // Opera 11.10
266
    background-image: linear-gradient(to bottom, @startColor, @endColor); // Standard, IE10
267
    background-repeat: repeat-x;
268
    filter: e(%("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=0)",argb(@startColor),argb(@endColor))); // IE9 and down
269
  }
270
  .directional(@startColor: #555, @endColor: #333, @deg: 45deg) {
271
272
    background-color: @endColor;
    background-repeat: repeat-x;
273
274
275
    background-image: -moz-linear-gradient(@deg, @startColor, @endColor); // FF 3.6+
    background-image: -webkit-linear-gradient(@deg, @startColor, @endColor); // Safari 5.1+, Chrome 10+
    background-image: -o-linear-gradient(@deg, @startColor, @endColor); // Opera 11.10
276
    background-image: linear-gradient(@deg, @startColor, @endColor); // Standard, IE10
277
  }
Francisco arenas's avatar
Francisco arenas committed
278
279
280
281
282
283
284
285
286
287
288
  .horizontal-three-colors(@startColor: #00b3ee, @midColor: #7a43b6, @colorStop: 50%, @endColor: #c3325f) {
    background-color: mix(@midColor, @endColor, 80%);
    background-image: -webkit-gradient(left, linear, 0 0, 0 100%, from(@startColor), color-stop(@colorStop, @midColor), to(@endColor));
    background-image: -webkit-linear-gradient(left, @startColor, @midColor @colorStop, @endColor);
    background-image: -moz-linear-gradient(left, @startColor, @midColor @colorStop, @endColor);
    background-image: -o-linear-gradient(left, @startColor, @midColor @colorStop, @endColor);
    background-image: linear-gradient(to right, @startColor, @midColor @colorStop, @endColor);
    background-repeat: no-repeat;
    filter: e(%("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=0)",argb(@startColor),argb(@endColor))); // IE9 and down, gets no color-stop at all for proper fallback
  }

sankage's avatar
sankage committed
289
  .vertical-three-colors(@startColor: #00b3ee, @midColor: #7a43b6, @colorStop: 50%, @endColor: #c3325f) {
290
    background-color: mix(@midColor, @endColor, 80%);
291
    background-image: -webkit-gradient(linear, 0 0, 0 100%, from(@startColor), color-stop(@colorStop, @midColor), to(@endColor));
sankage's avatar
sankage committed
292
    background-image: -webkit-linear-gradient(@startColor, @midColor @colorStop, @endColor);
293
    background-image: -moz-linear-gradient(top, @startColor, @midColor @colorStop, @endColor);
sankage's avatar
sankage committed
294
295
    background-image: -o-linear-gradient(@startColor, @midColor @colorStop, @endColor);
    background-image: linear-gradient(@startColor, @midColor @colorStop, @endColor);
296
    background-repeat: no-repeat;
297
    filter: e(%("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=0)",argb(@startColor),argb(@endColor))); // IE9 and down, gets no color-stop at all for proper fallback
298
  }
299
  .radial(@innerColor: #555, @outerColor: #333) {
300
301
302
303
    background-color: @outerColor;
    background-image: -webkit-gradient(radial, center center, 0, center center, 460, from(@innerColor), to(@outerColor));
    background-image: -webkit-radial-gradient(circle, @innerColor, @outerColor);
    background-image: -moz-radial-gradient(circle, @innerColor, @outerColor);
304
    background-image: -o-radial-gradient(circle, @innerColor, @outerColor);
305
306
    background-repeat: no-repeat;
  }
307
  .striped(@color: #555, @angle: 45deg) {
Piotrek Okoński's avatar
Piotrek Okoński committed
308
    background-color: @color;
309
310
311
312
313
    background-image: -webkit-gradient(linear, 0 100%, 100% 0, color-stop(.25, rgba(255,255,255,.15)), color-stop(.25, transparent), color-stop(.5, transparent), color-stop(.5, rgba(255,255,255,.15)), color-stop(.75, rgba(255,255,255,.15)), color-stop(.75, transparent), to(transparent));
    background-image: -webkit-linear-gradient(@angle, rgba(255,255,255,.15) 25%, transparent 25%, transparent 50%, rgba(255,255,255,.15) 50%, rgba(255,255,255,.15) 75%, transparent 75%, transparent);
    background-image: -moz-linear-gradient(@angle, rgba(255,255,255,.15) 25%, transparent 25%, transparent 50%, rgba(255,255,255,.15) 50%, rgba(255,255,255,.15) 75%, transparent 75%, transparent);
    background-image: -o-linear-gradient(@angle, rgba(255,255,255,.15) 25%, transparent 25%, transparent 50%, rgba(255,255,255,.15) 50%, rgba(255,255,255,.15) 75%, transparent 75%, transparent);
    background-image: linear-gradient(@angle, rgba(255,255,255,.15) 25%, transparent 25%, transparent 50%, rgba(255,255,255,.15) 50%, rgba(255,255,255,.15) 75%, transparent 75%, transparent);
Piotrek Okoński's avatar
Piotrek Okoński committed
314
  }
315
}
316
317
// Reset filters for IE
.reset-filter() {
318
  filter: e(%("progid:DXImageTransform.Microsoft.gradient(enabled = false)"));
319
}
320

321

Danny Keane's avatar
Danny Keane committed
322
323
324
// RETINA IMAGE SUPPORT
// --------------------------------------------------

Mark Otto's avatar
Mark Otto committed
325
326
327
328
329
330
331
332
333
334
335
336
337
338
// Short retina mixin for setting background-image and -size
.retina-image(@file-1x, @file-2x, @width-1x, @height-1x) {
  background-image: url("@{file-1x}");

  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and (     -o-min-device-pixel-ratio: 2/1),
  only screen and (        min-device-pixel-ratio: 2),
  only screen and (                min-resolution: 192dpi),
  only screen and (                min-resolution: 2dppx) {
    background-image: url("@{file-2x}");
    background-size: @width-1x @height-1x;
  }
Danny Keane's avatar
Danny Keane committed
339
340
}

341
342
343
344

// COMPONENT MIXINS
// --------------------------------------------------

345
// Horizontal dividers
346
347
// -------------------------
// Dividers (basically an hr) within dropdowns and nav lists
348
.nav-divider(@top: #e5e5e5, @bottom: #fff) {
Jacob Thornton's avatar
Jacob Thornton committed
349
  height: 1px;
Mark Otto's avatar
Mark Otto committed
350
  margin: ((@line-height-base / 2) - 1) 0;
Jacob Thornton's avatar
Jacob Thornton committed
351
  overflow: hidden;
352
353
  background-color: @top;
  border-bottom: 1px solid @bottom;
354
355
}

356
357
358
359
360
361
362
// Button psuedo states
// -------------------------
// Easily pump out default styles, as well as :hover, :focus, :active,
// and disabled options for all buttons
.btn-pseudo-states(@background, @border) {
  background-color: @background;
  border-color: @border;
363

Mark Otto's avatar
Mark Otto committed
364
  &:hover,
365
  &:focus,
366
367
  &:active,
  &.active {
368
369
    background-color: darken(@background, 5%);
        border-color: darken(@border, 10%);
Mark Otto's avatar
Mark Otto committed
370
  }
371

372
  &.disabled,
373
  &[disabled],
374
  fieldset[disabled] & {
375
376
    &:hover,
    &:focus,
377
378
    &:active,
    &.active {
379
380
381
      background-color: @background;
          border-color: @border
    }
382
383
384
  }
}

385
386
387
388
// Navbar vertical align
// -------------------------
// Vertically center elements in the navbar.
// Example: an element has a height of 30px, so write out `.navbarVerticalAlign(30px);` to calculate the appropriate top margin.
Mark Otto's avatar
Mark Otto committed
389
.navbar-vertical-align(@element-height) {
390
391
  margin-top: ((@navbar-height - @element-height) / 2);
  margin-bottom: ((@navbar-height - @element-height) / 2);
392
393
}

394

395
396
397
398

// Grid System
// -----------

399
// Centered container element
400
401
.container-fixed() {
  margin-right: auto;
Jacob Thornton's avatar
Jacob Thornton committed
402
  margin-left: auto;
403
  .clear_float();
404
405
}

406
// Make a grid
407

408
// Creates a wrapper for a series of columns
409
.make-row() {
410
411
412
413
414
  // Negative margin the row out to align the content of columns
  margin-left:  (@grid-gutter-width / -2);
  margin-right: (@grid-gutter-width / -2);
  // Then clear the floated columns
  .clear_float();
415
}
416
// Generate the columns
417
.make-column(@columns) {
418
419
420
421
422
423
424
425
426
427
  @media (min-width: @grid-float-breakpoint) {
    float: left;
    // Calculate width based on number of columns available
    width: percentage(@columns / @grid-columns);
  }
  // Prevent columns from collapsing when empty
  min-height: 1px;
  // Set inner padding as gutters instead of margin
  padding-left:  (@grid-gutter-width / 2);
  padding-right: (@grid-gutter-width / 2);
428
}
429
// Generate the column offsets
430
.make-column-offset(@columns) {
431
432
433
434
435
436
437
438
439
440
441
442
443
  @media (min-width: @grid-float-breakpoint) {
    margin-left: percentage((@columns / @grid-columns));
  }
}
.make-column-push(@columns) {
  @media (min-width: @grid-float-breakpoint) {
    left: percentage((@columns / @grid-columns));
  }
}
.make-column-pull(@columns) {
  @media (min-width: @grid-float-breakpoint) {
    right: percentage((@columns / @grid-columns));
  }
444
445
}

446

447

448
449
// The Grid
.generate-grid-columns(@grid-columns) {
450

451
  // Default columns
Mark Otto's avatar
Mark Otto committed
452
453
454
  .col-span-X (@index) when (@index > 0) {
    .col-span-@{index} { .col-span-(@index); }
    .col-span-X((@index - 1));
455
  }
Mark Otto's avatar
Mark Otto committed
456
  .col-span-X(0) {}
457

458
  // Offsets (gaps between columns)
Mark Otto's avatar
Mark Otto committed
459
460
461
  .col-offset-X (@index) when (@index > 0) {
    .col-offset-@{index} { .col-offset-(@index); }
    .col-offset-X((@index - 1));
462
  }
Mark Otto's avatar
Mark Otto committed
463
  .col-offset-X (0) {}
464

465
  // Source ordering
Mark Otto's avatar
Mark Otto committed
466
467
468
  .col-push-X (@index) when (@index > 0) {
    .col-push-@{index} { .col-push-(@index); }
    .col-push-X((@index - 1));
469
  }
Mark Otto's avatar
Mark Otto committed
470
  .col-push-X (0) {}
471

472
  // Source ordering
Mark Otto's avatar
Mark Otto committed
473
474
475
  .col-pull-X (@index) when (@index > 0) {
    .col-pull-@{index} { .col-pull-(@index); }
    .col-pull-X((@index - 1));
476
  }
Mark Otto's avatar
Mark Otto committed
477
  .col-pull-X (0) {}
478

479
  // Apply the styles
Mark Otto's avatar
Mark Otto committed
480
  .col-span-(@columns) {
481
482
    width: percentage((@columns / @grid-columns));
  }
Mark Otto's avatar
Mark Otto committed
483
  .col-offset-(@columns) {
484
485
    margin-left: percentage((@columns / @grid-columns));
  }
Mark Otto's avatar
Mark Otto committed
486
  .col-push-(@columns) {
487
    left: percentage((@columns / @grid-columns));
488
  }
Mark Otto's avatar
Mark Otto committed
489
  .col-pull-(@columns) {
490
491
492
493
    right: percentage((@columns / @grid-columns));
  }

  // Generate .spanX and .offsetX
Mark Otto's avatar
Mark Otto committed
494
495
496
497
  .col-span-X(@grid-columns);
  .col-offset-X(@grid-columns);
  .col-push-X(@grid-columns);
  .col-pull-X(@grid-columns);
498
}
Mark Otto's avatar
Mark Otto committed
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530



// Framework mixins
// --------------------------------------------------

// Generate rem font-sizes with pixel fallbacks
// By default uses `@font-size-base` with an initial value of 14 (1.4rem or 14px)
.font-size(@font-size: @font-size-base) {
  @rem-size: (@font-size / 10);
  font-size: ~"@{font-size}px";
  font-size: ~"@{rem-size}rem";
}

// Generate form validation states
.formFieldState(@text-color: #555, @border-color: #ccc, @background-color: #f5f5f5) {
  // Color the label text
  .control-label {
    color: @text-color;
  }
  // Set the border and box shadow on specific inputs to match
  .input-with-feedback {
    padding-right: 32px; // to account for the feedback icon
    border-color: @border-color;
    .box-shadow(inset 0 1px 1px rgba(0,0,0,.075)); // Redeclare so transitions work
    &:focus {
      border-color: darken(@border-color, 10%);
      @shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 6px lighten(@border-color, 20%);
      .box-shadow(@shadow);
    }
  }
}