mixins.less 15.1 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
  &:-moz-placeholder {
58
59
    color: @color;
  }
60
  &:-ms-input-placeholder {
61
62
    color: @color;
  }
63
  &::-webkit-input-placeholder {
64
65
66
67
    color: @color;
  }
}

Mark Otto's avatar
Mark Otto committed
68
69
70
71
72
73
74
75
// Text overflow
// Requires inline-block or block for proper styling
.text-overflow() {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

76
77
// CSS image replacement
// Source: https://github.com/h5bp/html5-boilerplate/commit/aa0396eae757
78
.hide-text() {
79
80
  font: 0/0 a;
  color: transparent;
81
  text-shadow: none;
82
  background-color: transparent;
83
  border: 0;
84
}
85

86

87
88
89
// FONTS
// --------------------------------------------------

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

121

122
// FORMS
123
124
// --------------------------------------------------

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



145
146
147
// CSS3 PROPERTIES
// --------------------------------------------------

148
// Single side border-radius
149
.border-top-radius(@radius) {
150
151
  border-top-right-radius: @radius;
   border-top-left-radius: @radius;
152
153
}
.border-right-radius(@radius) {
154
155
  border-bottom-right-radius: @radius;
     border-top-right-radius: @radius;
Mark Otto's avatar
Mark Otto committed
156
157
}
.border-bottom-radius(@radius) {
158
159
  border-bottom-right-radius: @radius;
   border-bottom-left-radius: @radius;
Mark Otto's avatar
Mark Otto committed
160
161
}
.border-left-radius(@radius) {
162
163
  border-bottom-left-radius: @radius;
     border-top-left-radius: @radius;
164
165
}

166
// Drop shadows
Mark Otto's avatar
Mark Otto committed
167
.box-shadow(@shadow) {
168
  -webkit-box-shadow: @shadow; // iOS <4.3 & Android <4.1
169
          box-shadow: @shadow;
170
171
172
}

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

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

229
230
231
232
// 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
233
.backface-visibility(@visibility){
234
	-webkit-backface-visibility: @visibility;
235
236
	   -moz-backface-visibility: @visibility;
	        backface-visibility: @visibility;
237
238
}

239
// Background clipping
Mark Otto's avatar
Mark Otto committed
240
241
242
243
.background-clip(@clip) {
  -webkit-background-clip: @clip;
     -moz-background-clip: @clip;
          background-clip: @clip;
244
245
}

246
// Background sizing
247
.background-size(@size) {
Mark Otto's avatar
Mark Otto committed
248
249
250
251
  -webkit-background-size: @size;
     -moz-background-size: @size;
       -o-background-size: @size;
          background-size: @size;
252
253
}

254
255
256
257
258
259
260
// Box sizing
.box-sizing(@boxmodel) {
  -webkit-box-sizing: @boxmodel;
     -moz-box-sizing: @boxmodel;
          box-sizing: @boxmodel;
}

261
262
263
264
265
// 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
266
      -ms-user-select: @select;
267
268
269
270
       -o-user-select: @select;
          user-select: @select;
}

271
// Resize anything
272
.resizable(@direction) {
273
274
275
276
  resize: @direction; // Options: horizontal, vertical, both
  overflow: auto; // Safari fix
}

277
// CSS3 Content Columns
278
279
280
281
282
283
284
.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;
285
286
}

Synchro's avatar
Synchro committed
287
288
// Optional hyphenation
.hyphens(@mode: auto) {
Mark Otto's avatar
Mark Otto committed
289
  word-wrap: break-word;
Synchro's avatar
Synchro committed
290
291
292
  -webkit-hyphens: @mode;
     -moz-hyphens: @mode;
      -ms-hyphens: @mode;
Synchro's avatar
Synchro committed
293
       -o-hyphens: @mode;
Synchro's avatar
Synchro committed
294
295
296
          hyphens: @mode;
}

297
// Opacity
298
.opacity(@opacity) {
299
  opacity: @opacity / 100;
300
  filter: ~"alpha(opacity=@{opacity})"; // IE8
301
302
303
304
305
306
307
}



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

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

370

371
372
373
374

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

375
// Horizontal dividers
376
377
// -------------------------
// Dividers (basically an hr) within dropdowns and nav lists
378
.nav-divider(@top: #e5e5e5, @bottom: #fff) {
Jacob Thornton's avatar
Jacob Thornton committed
379
  height: 1px;
Mark Otto's avatar
Mark Otto committed
380
  margin: ((@line-height-base / 2) - 1) 0;
Jacob Thornton's avatar
Jacob Thornton committed
381
  overflow: hidden;
382
383
  background-color: @top;
  border-bottom: 1px solid @bottom;
384
385
}

386
// Button backgrounds
Mark Otto's avatar
Mark Otto committed
387
388
389
390
391
// ------------------
.buttonBackground(@background-start, @background-end, @text-color: #fff, @text-shadow: 0 -1px 0 rgba(0,0,0,.25)) {
  color: @text-color;
  text-shadow: @text-shadow;
  #gradient > .vertical(@background-start, @background-end);
392
  border-color: darken(@background-end, 7.5%);
393

Mark Otto's avatar
Mark Otto committed
394
  &:hover,
395
396
  &:active,
  &.active {
Mark Otto's avatar
Mark Otto committed
397
    color: @text-color;
Mark Otto's avatar
Mark Otto committed
398
    background-color: @background-end;
399
    background-position: 0 -15px;
Mark Otto's avatar
Mark Otto committed
400
401
  }
  &:active,
402
403
404
405
  &.active,
  &[disabled],
  &.disabled,
  fieldset[disabled] & {
Mark Otto's avatar
Mark Otto committed
406
    background-image: none;
407
408
409
  }
}

Mark Otto's avatar
Mark Otto committed
410

411
412
413
414
// 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
415
.navbar-vertical-align(@element-height) {
416
  margin-top: (@navbar-height - @element-height) / 2;
Mark Otto's avatar
Mark Otto committed
417
  margin-bottom: (@navbar-height - @element-height) / 2;
418
419
}

420

421
422
423
424

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

425
// Centered container element
426
427
.container-fixed() {
  margin-right: auto;
Jacob Thornton's avatar
Jacob Thornton committed
428
  margin-left: auto;
429
  .clear_float();
430
431
}

432
433
// Make a Grid
// Use .makeRow and .makeColumn to assign semantic layouts grid system behavior
434
435
436
437
438
439
440
441
442
443
444
445
// .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() {

446
}
447
.make-column(@columns) {
448
  float: left;
449
450
451
452
453
  padding: @grid-gutter-width;
  width: percentage(@columns / @grid-columns);
}
.make-column-offset(@columns) {
  margin-left: percentage(@columns / @grid-columns);
454
455
}

456

457
// The Grid
458
459
#grid {

460
  .core(@grid-column-width, @grid-gutter-width) {
461

Mark Otto's avatar
Mark Otto committed
462
    .spanX(@index) when (@index > 0) {
463
464
465
      (~".span@{index}") { .span(@index); }
      .spanX(@index - 1);
    }
Mark Otto's avatar
Mark Otto committed
466
    .spanX(0) {}
467

Mark Otto's avatar
Mark Otto committed
468
    .offsetX(@index) when (@index > 0) {
469
470
      (~".offset@{index}") { .offset(@index); }
      .offsetX(@index - 1);
471
    }
Mark Otto's avatar
Mark Otto committed
472
    .offsetX(0) {}
473

Mark Otto's avatar
Mark Otto committed
474
475
    // Base styles
    .offset(@columns) {
Mark Otto's avatar
Mark Otto committed
476
      margin-left: percentage(@columns / @grid-columns);
477
    }
Mark Otto's avatar
Mark Otto committed
478
    .span(@columns) {
Mark Otto's avatar
Mark Otto committed
479
      width: percentage(@columns / @grid-columns);
480
481
    }

Mark Otto's avatar
Mark Otto committed
482
    // Generate .spanX and .offsetX
Mark Otto's avatar
Mark Otto committed
483
484
    .spanX(@grid-columns);
    .offsetX(@grid-columns);
485
486
487

  }

488
}