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

5

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

// Clearfix
10
11
12
13
14
15
16
17
18
// 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.
19
.clearfix() {
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
158
       -o-transform: skew(@x, @y);
          transform: skew(@x, @y);
}
159
.translate3d(@x, @y, @z) {
160
161
162
163
  -webkit-transform: translate3d(@x, @y, @z);
     -moz-transform: translate3d(@x, @y, @z);
       -o-transform: translate3d(@x, @y, @z);
          transform: translate3d(@x, @y, @z);
164
}
165

166
167
168
169
// 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
170
.backface-visibility(@visibility){
171
	-webkit-backface-visibility: @visibility;
172
173
	   -moz-backface-visibility: @visibility;
	        backface-visibility: @visibility;
174
175
}

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

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

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

198
199
200
201
202
// 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
203
      -ms-user-select: @select;
204
205
206
207
       -o-user-select: @select;
          user-select: @select;
}

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

214
// CSS3 Content Columns
215
216
217
218
219
220
221
.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;
222
223
}

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

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



Mark Otto's avatar
Mark Otto committed
244
// GRADIENTS
245
246
// --------------------------------------------------

247
#gradient {
Mark Otto's avatar
Mark Otto committed
248
249
250
251
252
253
254
255
256
257
258

  // Horizontal gradient, from left to right
  //
  // Creates two color stops, start and end, by specifying a color and position for each color stop.
  // Color stops are not available in IE9 and below.
  .horizontal(@start-color: #555; @start-percent: 0%; @end-color: #333; @end-percent: 100%) {
    background-color: @end-color;
    background-image: -webkit-gradient(linear, @start-percent top, @end-percent top, from(@start-color), to(@end-color)); // Safari 4+, Chrome 2+
    background-image: -webkit-linear-gradient(left, color-stop(@start-color @start-percent), color-stop(@end-color @end-percent)); // Safari 5.1+, Chrome 10+
    background-image: -moz-linear-gradient(left, @start-color @start-percent, @end-color @end-percent); // FF 3.6+
    background-image:  linear-gradient(to right, @start-color @start-percent, @end-color @end-percent); // Standard, IE10
259
    background-repeat: repeat-x;
Mark Otto's avatar
Mark Otto committed
260
    filter: e(%("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=1)",argb(@start-color),argb(@end-color))); // IE9 and down
261
  }
Mark Otto's avatar
Mark Otto committed
262
263
264
265
266
267
268
269
270
271
272

  // Vertical gradient, from top to bottom
  //
  // Creates two color stops, start and end, by specifying a color and position for each color stop.
  // Color stops are not available in IE9 and below.
  .vertical(@start-color: #555; @start-percent: 0%; @end-color: #333; @end-percent: 100%) {
    background-color: @end-color;
    background-image: -webkit-gradient(linear, left @start-percent, left @end-percent, from(@start-color), to(@end-color)); // Safari 4+, Chrome 2+
    background-image: -webkit-linear-gradient(top, @start-color, @start-percent, @end-color, @end-percent); // Safari 5.1+, Chrome 10+
    background-image:  -moz-linear-gradient(top, @start-color @start-percent, @end-color @end-percent); // FF 3.6+
    background-image: linear-gradient(to bottom, @start-color @start-percent, @end-color @end-percent); // Standard, IE10
273
    background-repeat: repeat-x;
Mark Otto's avatar
Mark Otto committed
274
    filter: e(%("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=0)",argb(@start-color),argb(@end-color))); // IE9 and down
275
  }
Mark Otto's avatar
Mark Otto committed
276
277
278

  .directional(@start-color: #555, @end-color: #333, @deg: 45deg) {
    background-color: @end-color;
279
    background-repeat: repeat-x;
Mark Otto's avatar
Mark Otto committed
280
281
282
    background-image: -webkit-linear-gradient(@deg, @start-color, @end-color); // Safari 5.1+, Chrome 10+
    background-image: -moz-linear-gradient(@deg, @start-color, @end-color); // FF 3.6+
    background-image: linear-gradient(@deg, @start-color, @end-color); // Standard, IE10
283
  }
Mark Otto's avatar
Mark Otto committed
284
285
286
287
288
289
  .horizontal-three-colors(@start-color: #00b3ee, @mid-color: #7a43b6, @color-stop: 50%, @end-color: #c3325f) {
    background-color: mix(@mid-color, @end-color, 80%);
    background-image: -webkit-gradient(left, linear, 0 0, 0 100%, from(@start-color), color-stop(@color-stop, @mid-color), to(@end-color));
    background-image: -webkit-linear-gradient(left, @start-color, @mid-color @color-stop, @end-color);
    background-image: -moz-linear-gradient(left, @start-color, @mid-color @color-stop, @end-color);
    background-image: linear-gradient(to right, @start-color, @mid-color @color-stop, @end-color);
Francisco arenas's avatar
Francisco arenas committed
290
    background-repeat: no-repeat;
Mark Otto's avatar
Mark Otto committed
291
    filter: e(%("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=1)",argb(@start-color),argb(@end-color))); // IE9 and down, gets no color-stop at all for proper fallback
Francisco arenas's avatar
Francisco arenas committed
292
293
  }

Mark Otto's avatar
Mark Otto committed
294
295
296
297
298
299
  .vertical-three-colors(@start-color: #00b3ee, @mid-color: #7a43b6, @color-stop: 50%, @end-color: #c3325f) {
    background-color: mix(@mid-color, @end-color, 80%);
    background-image: -webkit-gradient(linear, 0 0, 0 100%, from(@start-color), color-stop(@color-stop, @mid-color), to(@end-color));
    background-image: -webkit-linear-gradient(@start-color, @mid-color @color-stop, @end-color);
    background-image: -moz-linear-gradient(top, @start-color, @mid-color @color-stop, @end-color);
    background-image: linear-gradient(@start-color, @mid-color @color-stop, @end-color);
300
    background-repeat: no-repeat;
Mark Otto's avatar
Mark Otto committed
301
    filter: e(%("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=0)",argb(@start-color),argb(@end-color))); // IE9 and down, gets no color-stop at all for proper fallback
302
  }
Mark Otto's avatar
Mark Otto committed
303
304
305
306
307
308
  .radial(@inner-color: #555, @outer-color: #333) {
    background-color: @outer-color;
    background-image: -webkit-gradient(radial, center center, 0, center center, 460, from(@inner-color), to(@outer-color));
    background-image: -webkit-radial-gradient(circle, @inner-color, @outer-color);
    background-image: -moz-radial-gradient(circle, @inner-color, @outer-color);
    background-image: radial-gradient(circle, @inner-color, @outer-color);
309
310
    background-repeat: no-repeat;
  }
311
  .striped(@color: #555, @angle: 45deg) {
Piotrek Okoński's avatar
Piotrek Okoński committed
312
    background-color: @color;
313
314
315
316
    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: 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
317
  }
318
}
Mark Otto's avatar
Mark Otto committed
319

320
// Reset filters for IE
Mark Otto's avatar
Mark Otto committed
321
322
323
//
// When you need to remove a gradient background, don't forget to use this to reset
// the IE filter for IE9 and below.
324
.reset-filter() {
325
  filter: e(%("progid:DXImageTransform.Microsoft.gradient(enabled = false)"));
326
}
327

328

Mark Otto's avatar
Mark Otto committed
329

Danny Keane's avatar
Danny Keane committed
330
331
332
// RETINA IMAGE SUPPORT
// --------------------------------------------------

Mark Otto's avatar
Mark Otto committed
333
334
335
336
337
338
339
340
341
342
343
344
345
346
// 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
347
348
}

349
350
351
352

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

353
// Horizontal dividers
354
355
// -------------------------
// Dividers (basically an hr) within dropdowns and nav lists
356
.nav-divider(@top: #e5e5e5, @bottom: #fff) {
Mark Otto's avatar
Mark Otto committed
357
  height: 2px; // 1px for background, one for border
358
  margin: ((@line-height-computed / 2) - 1) 0;
Jacob Thornton's avatar
Jacob Thornton committed
359
  overflow: hidden;
360
361
  background-color: @top;
  border-bottom: 1px solid @bottom;
362
363
}

364
365
366
367
// Button psuedo states
// -------------------------
// Easily pump out default styles, as well as :hover, :focus, :active,
// and disabled options for all buttons
368
369
.btn-pseudo-states(@color, @background, @border) {
  color: @color;
370
371
  background-color: @background;
  border-color: @border;
372

Mark Otto's avatar
Mark Otto committed
373
  &:hover,
374
  &:focus,
375
376
  &:active,
  &.active {
377
378
    background-color: darken(@background, 5%);
        border-color: darken(@border, 10%);
Mark Otto's avatar
Mark Otto committed
379
  }
380

381
  &.disabled,
382
  &[disabled],
383
  fieldset[disabled] & {
384
385
    &:hover,
    &:focus,
386
387
    &:active,
    &.active {
388
389
390
      background-color: @background;
          border-color: @border
    }
391
392
393
  }
}

394
395
396
397
// 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
398
.navbar-vertical-align(@element-height) {
399
400
  margin-top: ((@navbar-height - @element-height) / 2);
  margin-bottom: ((@navbar-height - @element-height) / 2);
401
402
}

403

404
405
406
407

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

408
// Centered container element
409
410
.container-fixed() {
  margin-right: auto;
Jacob Thornton's avatar
Jacob Thornton committed
411
  margin-left: auto;
412
  .clearfix();
413
414
}

415
// Make a grid
416

417
// Creates a wrapper for a series of columns
418
.make-row() {
419
  // Then clear the floated columns
420
  .clearfix();
421
422
423
424
425
426

  // Negative margin nested rows out to align the content of columns
  .row {
    margin-left:  (@grid-gutter-width / -2);
    margin-right: (@grid-gutter-width / -2);
  }
427
}
428
// Generate the columns
429
.make-column(@columns) {
430
431
432
433
  position: relative;
  // Float and set width: 100%; for easy stacking on mobile devices
  float: left;
  width: 100%;
434
435
  // Prevent columns from collapsing when empty
  min-height: 1px;
436
  // Inner gutter via padding
437
438
  padding-left:  (@grid-gutter-width / 2);
  padding-right: (@grid-gutter-width / 2);
439
440
441
442
443

  // Calculate width based on number of columns available
  @media (min-width: @grid-float-breakpoint) {
    width: percentage((@columns / @grid-columns));
  }
444
}
445
// Generate the column offsets
446
.make-column-offset(@columns) {
447
448
449
450
451
452
453
454
455
456
457
458
459
  @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));
  }
460
}
461

462
// Small grid columns
463
.generate-grid-columns(@grid-columns) {
464

465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
  .col-sm-X (@index) when (@index > 0) {
    .col-sm-@{index} { .col-sm-(@index); }
    .col-sm-X((@index - 1));
  }
  .col-sm-X (0) {}

  // Generate columns
  .col-sm-X(@grid-columns);

  // Apply the styles
  .col-sm-(@columns) {
    width: percentage((@columns / @grid-columns));
  }
}

// Large grid columns
.generate-large-grid-columns(@grid-columns) {

  .col-lg-X (@index) when (@index > 0) {
    .col-lg-@{index} { .col-lg-(@index); }
    .col-lg-X((@index - 1));
  }
  .col-lg-X (0) {}

  // Generate the columns
  .col-lg-X(@grid-columns);

  // Apply the styles
  .col-lg-(@columns) {
    width: percentage((@columns / @grid-columns));
495
  }
496

497
  // Offsets (gaps between columns)
Mark Otto's avatar
Mark Otto committed
498
499
500
  .col-offset-X (@index) when (@index > 0) {
    .col-offset-@{index} { .col-offset-(@index); }
    .col-offset-X((@index - 1));
501
  }
Mark Otto's avatar
Mark Otto committed
502
  .col-offset-X (0) {}
503

504
  // Source ordering
Mark Otto's avatar
Mark Otto committed
505
506
507
  .col-push-X (@index) when (@index > 0) {
    .col-push-@{index} { .col-push-(@index); }
    .col-push-X((@index - 1));
508
  }
Mark Otto's avatar
Mark Otto committed
509
  .col-push-X (0) {}
510

511
  // Source ordering
Mark Otto's avatar
Mark Otto committed
512
513
514
  .col-pull-X (@index) when (@index > 0) {
    .col-pull-@{index} { .col-pull-(@index); }
    .col-pull-X((@index - 1));
515
  }
Mark Otto's avatar
Mark Otto committed
516
  .col-pull-X (0) {}
517

518
  // Apply the styles
Mark Otto's avatar
Mark Otto committed
519
  .col-offset-(@columns) {
520
521
    margin-left: percentage((@columns / @grid-columns));
  }
Mark Otto's avatar
Mark Otto committed
522
  .col-push-(@columns) {
523
    left: percentage((@columns / @grid-columns));
524
  }
Mark Otto's avatar
Mark Otto committed
525
  .col-pull-(@columns) {
526
527
528
529
    right: percentage((@columns / @grid-columns));
  }

  // Generate .spanX and .offsetX
Mark Otto's avatar
Mark Otto committed
530
531
532
  .col-offset-X(@grid-columns);
  .col-push-X(@grid-columns);
  .col-pull-X(@grid-columns);
533
}
Mark Otto's avatar
Mark Otto committed
534
535
536
537
538
539
540



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

// Generate form validation states
541
.form-field-validation(@text-color: #555, @border-color: #ccc, @background-color: #f5f5f5) {
Mark Otto's avatar
Mark Otto committed
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
  // 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);
    }
  }
}