forms.less 9.5 KB
Newer Older
1
2
3
//
// Forms
// --------------------------------------------------
4

5

6
// Non-controls
Mark Otto's avatar
Mark Otto committed
7
// -------------------------
Jacob Thornton's avatar
Jacob Thornton committed
8
9

form {
Mark Otto's avatar
Mark Otto committed
10
  margin: 0;
11
12
13
14
15
16
}

fieldset {
  padding: 0;
  margin: 0;
  border: 0;
17
}
18

19
20
21
legend {
  display: block;
  width: 100%;
22
  padding: 0;
Mark Otto's avatar
Mark Otto committed
23
  margin-bottom: @line-height-computed;
24
  font-size: (@font-size-base * 1.5);
25
  line-height: inherit;
26
  color: @gray-dark;
27
  border: 0;
28
  border-bottom: 1px solid #e5e5e5;
29
}
30

31
label {
32
  display: inline-block;
33
  margin-bottom: 5px;
34
  font-weight: bold;
35
}
36

37
38
39
// Form controls
// -------------------------

40
// Shared size and type resets
41
select,
42
43
44
45
46
47
48
49
50
51
52
53
54
55
textarea,
input[type="text"],
input[type="password"],
input[type="datetime"],
input[type="datetime-local"],
input[type="date"],
input[type="month"],
input[type="time"],
input[type="week"],
input[type="number"],
input[type="email"],
input[type="url"],
input[type="search"],
input[type="tel"],
56
input[type="color"] {
Mark Otto's avatar
Mark Otto committed
57
  display: block;
58
  min-height: @input-height-base; // Make inputs at least the height of their button counterpart (base line-height + padding + border)
59
  padding: @padding-base-vertical @padding-base-horizontal;
60
61
  font-size: @font-size-base;
  line-height: @line-height-base;
62
  color: @gray;
63
  vertical-align: middle;
64
  background-color: @input-bg;
65
66
  border: 1px solid @input-border;
  border-radius: @input-border-radius;
Mark Otto's avatar
Mark Otto committed
67
  .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
68
  .transition(~"border-color ease-in-out .15s, box-shadow ease-in-out .15s");
69
70
71
72

  &:focus {
    border-color: rgba(82,168,236,.8);
    outline: 0;
73
    .box-shadow(~"inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(82,168,236,.6)");
74
  }
75
76
}

Mark Otto's avatar
Mark Otto committed
77
// Reset appearance properties for textual inputs and textarea
Mark Otto's avatar
Mark Otto committed
78
// Can't be on input[type=*] selectors or it's too specific
Mark Otto's avatar
Mark Otto committed
79
input,
Mark Otto's avatar
Mark Otto committed
80
select,
81
textarea {
Mark Otto's avatar
Mark Otto committed
82
  width: 100%;
Mark Otto's avatar
Mark Otto committed
83
}
Mark Otto's avatar
Mark Otto committed
84

85
86
87
88
89
90
91
92
93
94
95
// Reset width of input images, buttons, radios, checkboxes
input[type="file"],
input[type="image"],
input[type="submit"],
input[type="reset"],
input[type="button"],
input[type="radio"],
input[type="checkbox"] {
  width: auto; // Override of generic input selector
}

96
97
98
99
100
// Override content-box in Normalize (* isn't specific enough)
input[type="search"] {
  .box-sizing(border-box);
}

101
102
103
104
// Reset height since textareas have rows
textarea {
  height: auto;
}
Mark Otto's avatar
Mark Otto committed
105

Mark Otto's avatar
Mark Otto committed
106
// Position radios and checkboxes better
107
108
input[type="radio"],
input[type="checkbox"] {
109
  margin: 4px 0 0;
110
  margin-top: 1px \9; /* IE8-9 */
Mark Otto's avatar
Mark Otto committed
111
  line-height: normal;
112
}
Mark Otto's avatar
Mark Otto committed
113

114
// Set the height of select and file controls to match text inputs
115
select,
116
input[type="file"] {
117
118
  height: @input-height-base; /* In IE7, the height of the select element cannot be changed by height, only font-size. TODO: Check if this is still needed when dropping IE7 support */
  line-height: @input-height-base;
Mark Otto's avatar
Mark Otto committed
119
}
120

Mark Otto's avatar
Mark Otto committed
121
// Make multiple select elements height not fixed
122
123
select[multiple],
select[size] {
Mark Otto's avatar
Mark Otto committed
124
  height: auto;
Mark Otto's avatar
Mark Otto committed
125
126
}

127
128
129
130
131
132
// Focus for select, file, radio, and checkbox
input[type="file"]:focus,
input[type="radio"]:focus,
input[type="checkbox"]:focus {
  .tab-focus();
}
133

134

Mark Otto's avatar
Mark Otto committed
135
136
137
// Placeholder
// -------------------------

138
// Placeholder text gets special styles because when browsers invalidate entire lines if it doesn't understand a selector
Mark Otto's avatar
Mark Otto committed
139
140
141
142
143
input,
textarea {
  .placeholder();
}

144

145
146
147
148
149
150
// CHECKBOXES & RADIOS
// -------------------

// Indent the labels to position radios/checkboxes as hanging
.radio,
.checkbox {
151
  display: block;
Mark Otto's avatar
Mark Otto committed
152
  min-height: @line-height-computed; // clear the floating input if there is no label text
Mark Otto's avatar
Mark Otto committed
153
154
  margin-top: 10px;
  margin-bottom: 10px;
155
  padding-left: 20px;
Mark Otto's avatar
Mark Otto committed
156
  vertical-align: middle;
Mark Otto's avatar
Mark Otto committed
157
158
159
160
  label {
    display: inline;
    margin-bottom: 0;
    font-weight: normal;
161
    cursor: pointer;
Mark Otto's avatar
Mark Otto committed
162
  }
163
}
164
.radio input[type="radio"],
Mark Otto's avatar
Mark Otto committed
165
166
167
.radio-inline input[type="radio"],
.checkbox input[type="checkbox"],
.checkbox-inline input[type="checkbox"] {
168
  float: left;
169
  margin-left: -20px;
170
}
Mark Otto's avatar
Mark Otto committed
171
172
.radio + .radio,
.checkbox + .checkbox {
Mark Otto's avatar
Mark Otto committed
173
  margin-top: -5px; // Move up sibling radios or checkboxes for tighter spacing
Mark Otto's avatar
Mark Otto committed
174
}
175

Mark Otto's avatar
Mark Otto committed
176
/*
177
178
179
// Move the options list down to align with labels
.controls > .radio:first-child,
.controls > .checkbox:first-child {
180
  padding-top: 5px; // has to be padding because margin collaspes
181
}
Mark Otto's avatar
Mark Otto committed
182
*/
183

184
// Radios and checkboxes on same line
Mark Otto's avatar
Mark Otto committed
185
186
.radio-inline,
.checkbox-inline {
187
  display: inline-block;
Mark Otto's avatar
Mark Otto committed
188
//  padding-top: 5px;
Mark Otto's avatar
Mark Otto committed
189
  padding-left: 20px;
190
  margin-bottom: 0;
191
  vertical-align: middle;
Mark Otto's avatar
Mark Otto committed
192
  font-weight: normal;
193
  cursor: pointer;
194
}
Mark Otto's avatar
Mark Otto committed
195
196
197
.radio-inline + .radio-inline,
.checkbox-inline + .checkbox-inline {
  margin-top: 0;
198
  margin-left: 10px; // space out consecutive inline controls
199
200
}

201
202


203
204
205
// INPUT SIZES
// -----------

206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
select,
textarea,
input[type="text"],
input[type="password"],
input[type="datetime"],
input[type="datetime-local"],
input[type="date"],
input[type="month"],
input[type="time"],
input[type="week"],
input[type="number"],
input[type="email"],
input[type="url"],
input[type="search"],
input[type="tel"],
221
input[type="color"] {
222
  &.input-large {
223
    padding: @padding-large-vertical @padding-large-horizontal;
224
225
    font-size: @font-size-large;
    border-radius: @border-radius-large;
226
227
  }
  &.input-small {
228
    min-height: @input-height-small;
229
    padding: @padding-small-vertical @padding-small-horizontal;
230
231
    font-size: @font-size-small;
    border-radius: @border-radius-small;
232
233
  }
}
234

Mark Otto's avatar
Mark Otto committed
235

236
237
// DISABLED STATE
// --------------
238

239
// Disabled and read-only inputs
240
241
242
// Note: HTML5 says that inputs under a fieldset > legend:first-child won't be
//   disabled if the fieldset is disabled. Due to implementation difficulty,
//   we don't honor that edge case; we style them as disabled anyway.
243
244
245
246
247
248
249
input,
select,
textarea {
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    cursor: not-allowed;
250
    background-color: @input-bg-disabled;
251
  }
Jacob Thornton's avatar
Jacob Thornton committed
252
}
253
// Explicitly reset the colors here
254
255
256
257
258
259
260
input[type="radio"],
input[type="checkbox"] {
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    background-color: transparent;
  }
261
}
Jacob Thornton's avatar
Jacob Thornton committed
262

263
264


265

266
267
// FORM FIELD FEEDBACK STATES
// --------------------------
268

269
// Warning
270
.has-warning {
271
  .form-field-validation(@state-warning-text, @state-warning-text, @state-warning-bg);
272
273
}
// Error
274
.has-error {
275
  .form-field-validation(@state-danger-text, @state-danger-text, @state-danger-bg);
276
277
}
// Success
278
.has-success {
279
  .form-field-validation(@state-success-text, @state-success-text, @state-success-bg);
280
}
281

282
283
// HTML5 invalid states
// Shares styles with the .control-group.error above
Mark Otto's avatar
Mark Otto committed
284
285
286
input:focus:invalid,
textarea:focus:invalid,
select:focus:invalid {
287
288
289
290
  color: #b94a48;
  border-color: #ee5f5b;
  &:focus {
    border-color: darken(#ee5f5b, 10%);
291
292
    @shadow: 0 0 6px lighten(#ee5f5b, 20%);
    .box-shadow(@shadow);
293
294
295
  }
}

296
297
298



299
300
301
// HELP TEXT
// ---------

302
.help-block {
303
  display: block; // account for any element using help-block
Mark Otto's avatar
Mark Otto committed
304
305
306
  margin-top: 5px;
  margin-bottom: 10px;
  color: lighten(@text-color, 25%); // lighten the text some for contrast
Jacob Thornton's avatar
Jacob Thornton committed
307
}
308

309

310

Mark Otto's avatar
Mark Otto committed
311
312
// Input groups
// --------------------------------------------------
313

Mark Otto's avatar
Mark Otto committed
314
315
316
317
// Base styles
// -------------------------
.input-group {
  display: table;
318

Mark Otto's avatar
Mark Otto committed
319
  // Undo padding and float of grid classes
Mark Otto's avatar
Mark Otto committed
320
  &.col {
Mark Otto's avatar
Mark Otto committed
321
    float: none;
Mark Otto's avatar
Mark Otto committed
322
323
    padding-left: 0;
    padding-right: 0;
324
  }
325

326
  input,
327
  select {
Mark Otto's avatar
Mark Otto committed
328
    width: 100%;
Mark Otto's avatar
Mark Otto committed
329
    margin-bottom: 0;
330
331
  }
}
332

Mark Otto's avatar
Mark Otto committed
333
334
335
336
// Display as table-cell
// -------------------------
.input-group-addon,
.input-group-btn,
337
.input-group input {
Mark Otto's avatar
Mark Otto committed
338
  display: table-cell;
339
340

  &:not(:first-child):not(:last-child) {
341
342
    border-radius: 0;
  }
Jacob Thornton's avatar
Jacob Thornton committed
343
}
Mark Otto's avatar
Mark Otto committed
344
345
346
347
348
// Addon and addon wrapper for buttons
.input-group-addon,
.input-group-btn {
  width: 1%;
  vertical-align: middle; // Match the inputs
349
350
}

Mark Otto's avatar
Mark Otto committed
351
352
353
354
355
356
357
358
359
360
// Text input groups
// -------------------------
.input-group-addon {
  .box-sizing(border-box);
  padding: 6px 8px;
  font-size: @font-size-base;
  font-weight: normal;
  line-height: @line-height-base;
  text-align: center;
  text-shadow: 0 1px 0 #fff;
361
  background-color: @gray-lighter;
Mark Otto's avatar
Mark Otto committed
362
  border: 1px solid #ccc;
363
  border-radius: @border-radius-base;
364

Mark Otto's avatar
Mark Otto committed
365
  &.input-small {
366
    padding: @padding-small-vertical @padding-small-horizontal;
Mark Otto's avatar
Mark Otto committed
367
    font-size: @font-size-small;
368
369
    border-radius: @border-radius-small;
  }
Mark Otto's avatar
Mark Otto committed
370
  &.input-large {
371
    padding: @padding-large-vertical @padding-large-horizontal;
Mark Otto's avatar
Mark Otto committed
372
    font-size: @font-size-large;
373
    border-radius: @border-radius-large;
374
  }
375
}
Mark Otto's avatar
Mark Otto committed
376
377
378

// Reset rounded corners
.input-group input:first-child,
379
.input-group-addon:first-child,
380
381
382
.input-group-btn:first-child > .btn,
.input-group-btn:first-child > .dropdown-toggle,
.input-group-btn:last-child > .btn:not(:last-child):not(.dropdown-toggle) {
383
  .border-right-radius(0);
384
}
Mark Otto's avatar
Mark Otto committed
385
386
.input-group-addon:first-child {
  border-right: 0;
387
}
Mark Otto's avatar
Mark Otto committed
388
.input-group input:last-child,
389
.input-group-addon:last-child,
390
391
392
.input-group-btn:last-child > .btn,
.input-group-btn:last-child > .dropdown-toggle,
.input-group-btn:first-child > .btn:not(:first-child) {
393
  .border-left-radius(0);
394
}
Mark Otto's avatar
Mark Otto committed
395
396
.input-group-addon:last-child {
  border-left: 0;
397
398
}

Mark Otto's avatar
Mark Otto committed
399
400
// Button input groups
// -------------------------
401
402
.input-group-btn {
  position: relative;
Mark Otto's avatar
Mark Otto committed
403
  white-space: nowrap;
404
}
Mark Otto's avatar
Mark Otto committed
405
.input-group-btn > .btn {
406
  position: relative;
Mark Otto's avatar
Mark Otto committed
407
408
  float: left; // Collapse white-space
  + .btn {
409
    margin-left: -1px;
410
  }
411
412
413
414
  // Bring the "active" button to the front
  &:hover,
  &:active {
    z-index: 2;
415
  }
Mark Otto's avatar
Mark Otto committed
416
}
417

Mark Otto's avatar
Mark Otto committed
418

Mark Otto's avatar
Mark Otto committed
419
420
421
422
423
424
425
426
427
428
// Inline forms
// --------------------------------------------------

.form-inline {
  input,
  select,
  textarea,
  .radio,
  .checkbox {
    display: inline-block;
Mark Otto's avatar
Mark Otto committed
429
430
431
432
  }
  .radio,
  .checkbox {
    margin-top: 0;
Mark Otto's avatar
Mark Otto committed
433
434
435
436
437
    margin-bottom: 0;
  }
}


Mark Otto's avatar
Mark Otto committed
438
439
// Horizontal forms
// --------------------------------------------------
Mark Otto's avatar
Mark Otto committed
440
// Horizontal forms are built on grid classes.
Mark Otto's avatar
Mark Otto committed
441

Mark Otto's avatar
Mark Otto committed
442
443
444
445
.form-horizontal {
  .row + .row {
    margin-top: 15px;
  }
446
  .control-label {
Mark Otto's avatar
Mark Otto committed
447
    padding-top: 6px;
448
449
450
451
452
  }
}

// Only right aline form labels here when the columns stop stacking
@media (min-width: 768px) {
453
  .form-horizontal .control-label {
Mark Otto's avatar
Mark Otto committed
454
    text-align: right;
Mark Otto's avatar
Mark Otto committed
455
  }
Mark Otto's avatar
Mark Otto committed
456
}