mixins.less 16.2 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
// FONTS
// --------------------------------------------------

85
#font {
86
87
  #family {
    .serif() {
Mark Otto's avatar
Mark Otto committed
88
      font-family: @font-family-serif;
89
90
    }
    .sans-serif() {
Mark Otto's avatar
Mark Otto committed
91
      font-family: @font-family-sans-serif;
92
93
    }
    .monospace() {
Mark Otto's avatar
Mark Otto committed
94
      font-family: @font-family-monospace;
95
    }
96
  }
97
  .shorthand(@size: @font-size-base, @weight: normal, @lineHeight: @line-height-base) {
98
99
100
101
    font-size: @size;
    font-weight: @weight;
    line-height: @lineHeight;
  }
102
  .serif(@size: @font-size-base, @weight: normal, @lineHeight: @line-height-base) {
103
104
    #font > #family > .serif;
    #font > .shorthand(@size, @weight, @lineHeight);
105
  }
106
  .sans-serif(@size: @font-size-base, @weight: normal, @lineHeight: @line-height-base) {
107
108
109
    #font > #family > .sans-serif;
    #font > .shorthand(@size, @weight, @lineHeight);
  }
110
  .monospace(@size: @font-size-base, @weight: normal, @lineHeight: @line-height-base) {
111
112
    #font > #family > .monospace;
    #font > .shorthand(@size, @weight, @lineHeight);
113
114
115
  }
}

116

117
// FORMS
118
119
// --------------------------------------------------

120
.formFieldState(@text-color: #555, @border-color: #ccc, @background-color: #f5f5f5) {
121
122
  // Color the label text
  .control-label {
Mark Otto's avatar
Mark Otto committed
123
    color: @text-color;
124
  }
125
126
127
  // Set the border and box shadow on specific inputs to match
  .input-with-feedback {
    padding-right: 32px; // to account for the feedback icon
128
    border-color: @border-color;
129
    .box-shadow(inset 0 1px 1px rgba(0,0,0,.075)); // Redeclare so transitions work
130
    &:focus {
131
132
      border-color: darken(@border-color, 10%);
      @shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 6px lighten(@border-color, 20%);
133
      .box-shadow(@shadow);
134
135
136
137
138
139
    }
  }
}



140
141
142
// CSS3 PROPERTIES
// --------------------------------------------------

143
// Single side border-radius
144
.border-top-radius(@radius) {
145
146
  border-top-right-radius: @radius;
   border-top-left-radius: @radius;
147
148
}
.border-right-radius(@radius) {
149
150
  border-bottom-right-radius: @radius;
     border-top-right-radius: @radius;
Mark Otto's avatar
Mark Otto committed
151
152
}
.border-bottom-radius(@radius) {
153
154
  border-bottom-right-radius: @radius;
   border-bottom-left-radius: @radius;
Mark Otto's avatar
Mark Otto committed
155
156
}
.border-left-radius(@radius) {
157
158
  border-bottom-left-radius: @radius;
     border-top-left-radius: @radius;
159
160
}

161
// Drop shadows
Mark Otto's avatar
Mark Otto committed
162
.box-shadow(@shadow) {
163
  -webkit-box-shadow: @shadow; // iOS <4.3 & Android <4.1
164
          box-shadow: @shadow;
165
166
167
}

// Transitions
Mark Otto's avatar
Mark Otto committed
168
169
170
171
172
.transition(@transition) {
  -webkit-transition: @transition;
     -moz-transition: @transition;
       -o-transition: @transition;
          transition: @transition;
173
}
Tunghsiao Liu's avatar
Tunghsiao Liu committed
174
175
176
177
178
179
.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
180
181
182
183
184
185
.transition-duration(@transition-duration) {
  -webkit-transition-duration: @transition-duration;
     -moz-transition-duration: @transition-duration;
       -o-transition-duration: @transition-duration;
          transition-duration: @transition-duration;
}
186

Mark Otto's avatar
Mark Otto committed
187
// Transformations
188
.rotate(@degrees) {
189
190
  -webkit-transform: rotate(@degrees);
     -moz-transform: rotate(@degrees);
Mark Otto's avatar
Mark Otto committed
191
192
      -ms-transform: rotate(@degrees);
       -o-transform: rotate(@degrees);
193
194
          transform: rotate(@degrees);
}
195
196
197
198
199
200
.scale(@ratio) {
  -webkit-transform: scale(@ratio);
     -moz-transform: scale(@ratio);
      -ms-transform: scale(@ratio);
       -o-transform: scale(@ratio);
          transform: scale(@ratio);
201
}
202
.translate(@x, @y) {
Mark Otto's avatar
Mark Otto committed
203
204
205
206
207
208
  -webkit-transform: translate(@x, @y);
     -moz-transform: translate(@x, @y);
      -ms-transform: translate(@x, @y);
       -o-transform: translate(@x, @y);
          transform: translate(@x, @y);
}
209
.skew(@x, @y) {
Mark Otto's avatar
Mark Otto committed
210
211
  -webkit-transform: skew(@x, @y);
     -moz-transform: skew(@x, @y);
212
      -ms-transform: skewX(@x) skewY(@y); // See https://github.com/twitter/bootstrap/issues/4885
Mark Otto's avatar
Mark Otto committed
213
214
       -o-transform: skew(@x, @y);
          transform: skew(@x, @y);
215
  -webkit-backface-visibility: hidden; // See https://github.com/twitter/bootstrap/issues/5319
Mark Otto's avatar
Mark Otto committed
216
}
217
.translate3d(@x, @y, @z) {
218
219
220
221
  -webkit-transform: translate3d(@x, @y, @z);
     -moz-transform: translate3d(@x, @y, @z);
       -o-transform: translate3d(@x, @y, @z);
          transform: translate3d(@x, @y, @z);
222
}
223

224
225
226
227
// 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
228
.backface-visibility(@visibility){
229
	-webkit-backface-visibility: @visibility;
230
231
	   -moz-backface-visibility: @visibility;
	        backface-visibility: @visibility;
232
233
}

234
// Background clipping
Mark Otto's avatar
Mark Otto committed
235
236
237
238
.background-clip(@clip) {
  -webkit-background-clip: @clip;
     -moz-background-clip: @clip;
          background-clip: @clip;
239
240
}

241
// Background sizing
242
.background-size(@size) {
Mark Otto's avatar
Mark Otto committed
243
244
245
246
  -webkit-background-size: @size;
     -moz-background-size: @size;
       -o-background-size: @size;
          background-size: @size;
247
248
}

249
250
251
252
253
254
255
// Box sizing
.box-sizing(@boxmodel) {
  -webkit-box-sizing: @boxmodel;
     -moz-box-sizing: @boxmodel;
          box-sizing: @boxmodel;
}

256
257
258
259
260
// 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
261
      -ms-user-select: @select;
262
263
264
265
       -o-user-select: @select;
          user-select: @select;
}

266
// Resize anything
267
.resizable(@direction) {
268
269
270
271
  resize: @direction; // Options: horizontal, vertical, both
  overflow: auto; // Safari fix
}

272
// CSS3 Content Columns
273
274
275
276
277
278
279
.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;
280
281
}

Synchro's avatar
Synchro committed
282
283
// Optional hyphenation
.hyphens(@mode: auto) {
Mark Otto's avatar
Mark Otto committed
284
  word-wrap: break-word;
Synchro's avatar
Synchro committed
285
286
287
  -webkit-hyphens: @mode;
     -moz-hyphens: @mode;
      -ms-hyphens: @mode;
Synchro's avatar
Synchro committed
288
       -o-hyphens: @mode;
Synchro's avatar
Synchro committed
289
290
291
          hyphens: @mode;
}

292
// Opacity
293
.opacity(@opacity) {
294
295
  opacity: @opacity;
  // IE8 filter
296
  @opacity-ie: (@opacity * 100);
297
  filter: ~"alpha(opacity=@{opacity-ie})";
298
299
300
301
302
303
304
}



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

305
306
// Gradients
#gradient {
307
  .horizontal(@startColor: #555, @endColor: #333) {
308
309
    background-color: @endColor;
    background-image: -moz-linear-gradient(left, @startColor, @endColor); // FF 3.6+
310
    background-image: -webkit-gradient(linear, 0 0, 100% 0, from(@startColor), to(@endColor)); // Safari 4+, Chrome 2+
311
312
    background-image: -webkit-linear-gradient(left, @startColor, @endColor); // Safari 5.1+, Chrome 10+
    background-image: -o-linear-gradient(left, @startColor, @endColor); // Opera 11.10
313
    background-image: linear-gradient(to right, @startColor, @endColor); // Standard, IE10
314
    background-repeat: repeat-x;
315
    filter: e(%("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=1)",argb(@startColor),argb(@endColor))); // IE9 and down
316
  }
317
  .vertical(@startColor: #555, @endColor: #333) {
318
    background-color: @endColor;
Mark Otto's avatar
Mark Otto committed
319
    background-image: -moz-linear-gradient(top, @startColor, @endColor); // FF 3.6+
320
    background-image: -webkit-gradient(linear, 0 0, 0 100%, from(@startColor), to(@endColor)); // Safari 4+, Chrome 2+
Mark Otto's avatar
Mark Otto committed
321
322
    background-image: -webkit-linear-gradient(top, @startColor, @endColor); // Safari 5.1+, Chrome 10+
    background-image: -o-linear-gradient(top, @startColor, @endColor); // Opera 11.10
323
    background-image: linear-gradient(to bottom, @startColor, @endColor); // Standard, IE10
324
    background-repeat: repeat-x;
325
    filter: e(%("progid:DXImageTransform.Microsoft.gradient(startColorstr='%d', endColorstr='%d', GradientType=0)",argb(@startColor),argb(@endColor))); // IE9 and down
326
  }
327
  .directional(@startColor: #555, @endColor: #333, @deg: 45deg) {
328
329
    background-color: @endColor;
    background-repeat: repeat-x;
330
331
332
    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
333
    background-image: linear-gradient(@deg, @startColor, @endColor); // Standard, IE10
334
  }
Francisco arenas's avatar
Francisco arenas committed
335
336
337
338
339
340
341
342
343
344
345
  .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
346
  .vertical-three-colors(@startColor: #00b3ee, @midColor: #7a43b6, @colorStop: 50%, @endColor: #c3325f) {
347
    background-color: mix(@midColor, @endColor, 80%);
348
    background-image: -webkit-gradient(linear, 0 0, 0 100%, from(@startColor), color-stop(@colorStop, @midColor), to(@endColor));
sankage's avatar
sankage committed
349
    background-image: -webkit-linear-gradient(@startColor, @midColor @colorStop, @endColor);
350
    background-image: -moz-linear-gradient(top, @startColor, @midColor @colorStop, @endColor);
sankage's avatar
sankage committed
351
352
    background-image: -o-linear-gradient(@startColor, @midColor @colorStop, @endColor);
    background-image: linear-gradient(@startColor, @midColor @colorStop, @endColor);
353
    background-repeat: no-repeat;
354
    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
355
  }
356
  .radial(@innerColor: #555, @outerColor: #333) {
357
358
359
360
    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);
361
    background-image: -o-radial-gradient(circle, @innerColor, @outerColor);
362
363
    background-repeat: no-repeat;
  }
364
  .striped(@color: #555, @angle: 45deg) {
Piotrek Okoński's avatar
Piotrek Okoński committed
365
    background-color: @color;
366
367
368
369
370
    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
371
  }
372
}
373
374
// Reset filters for IE
.reset-filter() {
375
  filter: e(%("progid:DXImageTransform.Microsoft.gradient(enabled = false)"));
376
}
377

378

379
380
381
382

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

383
// Horizontal dividers
384
385
// -------------------------
// Dividers (basically an hr) within dropdowns and nav lists
386
.nav-divider(@top: #e5e5e5, @bottom: #fff) {
Jacob Thornton's avatar
Jacob Thornton committed
387
  height: 1px;
Mark Otto's avatar
Mark Otto committed
388
  margin: ((@line-height-base / 2) - 1) 0;
Jacob Thornton's avatar
Jacob Thornton committed
389
  overflow: hidden;
390
391
  background-color: @top;
  border-bottom: 1px solid @bottom;
392
393
}

394
395
396
397
398
399
400
// 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;
401

Mark Otto's avatar
Mark Otto committed
402
  &:hover,
403
404
405
406
  &:focus,
  &:active {
    background-color: darken(@background, 5%);
        border-color: darken(@border, 10%);
Mark Otto's avatar
Mark Otto committed
407
  }
408

409
  &.disabled,
410
  &[disabled],
411
  fieldset[disabled] & {
412
413
414
415
416
417
    &:hover,
    &:focus,
    &:active {
      background-color: @background;
          border-color: @border
    }
418
419
420
  }
}

421
422
423
424
// 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
425
.navbar-vertical-align(@element-height) {
426
427
  margin-top: ((@navbar-height - @element-height) / 2);
  margin-bottom: ((@navbar-height - @element-height) / 2);
428
429
}

430

431
432
433
434

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

435
// Centered container element
436
437
.container-fixed() {
  margin-right: auto;
Jacob Thornton's avatar
Jacob Thornton committed
438
  margin-left: auto;
439
  .clear_float();
440
441
}

442
443
// Make a Grid
// Use .makeRow and .makeColumn to assign semantic layouts grid system behavior
444
445
446
447
448
449
450
451
452
453
454
455
// .makeRow() {
//   margin-left: @grid-gutter-width * -1;
//   .clearfix();
// }
// .makeColumn(@columns: 1, @offset: 0) {
//   float: left;
//   margin-left: (@grid-column-width * @offset) + (@grid-gutter-width * (@offset - 1)) + (@grid-gutter-width * 2);
//   width: (@grid-column-width * @columns) + (@grid-gutter-width * (@columns - 1));
// }

.make-row() {

456
}
457
.make-column(@columns) {
458
  float: left;
459
460
461
462
463
  padding: @grid-gutter-width;
  width: percentage(@columns / @grid-columns);
}
.make-column-offset(@columns) {
  margin-left: percentage(@columns / @grid-columns);
464
465
}

466

467
// The Grid
468
469
#grid {

470
  .core(@grid-column-width, @grid-gutter-width) {
471

472
    .spanX (@index) when (@index > 0) {
473
      .span@{index} { .span(@index); }
474
      .spanX((@index - 1));
475
    }
Mark Otto's avatar
Mark Otto committed
476
    .spanX(0) {}
477

Igor Rzegocki's avatar
Igor Rzegocki committed
478
    .offsetX (@index) when (@index > 0) {
479
      .offset@{index} { .offset(@index); }
480
      .offsetX((@index - 1));
481
    }
Igor Rzegocki's avatar
Igor Rzegocki committed
482
    .offsetX (0) {}
483

Mark Otto's avatar
Mark Otto committed
484
485
    // Base styles
    .offset(@columns) {
486
      margin-left: percentage((@columns / @grid-columns));
487
    }
Mark Otto's avatar
Mark Otto committed
488
    .span(@columns) {
489
      width: percentage((@columns / @grid-columns));
490
491
    }

Mark Otto's avatar
Mark Otto committed
492
    // Generate .spanX and .offsetX
Mark Otto's avatar
Mark Otto committed
493
494
    .spanX(@grid-columns);
    .offsetX(@grid-columns);
495
496

  }
497
}