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

5

Mark Otto's avatar
Mark Otto committed
6
7
8
// Normalize non-controls
//
// Restyle and baseline non-control form elements.
9
10
11
12
13

fieldset {
  padding: 0;
  margin: 0;
  border: 0;
14
}
15

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

28
label {
29
  display: inline-block;
30
  margin-bottom: 5px;
31
  font-weight: bold;
32
}
33

34

Mark Otto's avatar
Mark Otto committed
35
// Normalize form controls
36

37
38
39
40
41
// Override content-box in Normalize (* isn't specific enough)
input[type="search"] {
  .box-sizing(border-box);
}

Mark Otto's avatar
Mark Otto committed
42
// Position radios and checkboxes better
43
44
input[type="radio"],
input[type="checkbox"] {
45
  margin: 4px 0 0;
46
  margin-top: 1px \9; /* IE8-9 */
Mark Otto's avatar
Mark Otto committed
47
  line-height: normal;
48
}
Mark Otto's avatar
Mark Otto committed
49

50
// Set the height of select and file controls to match text inputs
51
input[type="file"] {
52
  display: block;
Mark Otto's avatar
Mark Otto committed
53
}
54

Mark Otto's avatar
Mark Otto committed
55
// Make multiple select elements height not fixed
56
57
select[multiple],
select[size] {
Mark Otto's avatar
Mark Otto committed
58
  height: auto;
Mark Otto's avatar
Mark Otto committed
59
60
}

Chris Rebert's avatar
Chris Rebert committed
61
// Fix optgroup Firefox bug per https://github.com/twbs/bootstrap/issues/7611
62
63
64
65
66
67
select optgroup {
  font-size: inherit;
  font-style: inherit;
  font-family: inherit;
}

68
69
70
71
72
73
// Focus for select, file, radio, and checkbox
input[type="file"]:focus,
input[type="radio"]:focus,
input[type="checkbox"]:focus {
  .tab-focus();
}
74

75
76
// Fix for Chrome number input
// Setting certain font-sizes causes the `I` bar to appear on hover of the bottom increment button.
Chris Rebert's avatar
Chris Rebert committed
77
// See https://github.com/twbs/bootstrap/issues/8350 for more.
78
input[type="number"] {
79
  &::-webkit-outer-spin-button,
Chris Rebert's avatar
Chris Rebert committed
80
  &::-webkit-inner-spin-button {
81
82
83
84
    height: auto;
  }
}

85

Mark Otto's avatar
Mark Otto committed
86
// Placeholder
Mark Otto's avatar
Mark Otto committed
87
88
89
90
//
// Placeholder text gets special styles because when browsers invalidate entire
// lines if it doesn't understand a selector/
.form-control {
Mark Otto's avatar
Mark Otto committed
91
92
93
  .placeholder();
}

94

Mark Otto's avatar
Mark Otto committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// Common form controls
//
// Shared size and type resets for form controls. Apply `.form-control` to any
// of the following form controls:
//
// 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"]
// input[type="color"]

.form-control {
  display: block;
  width: 100%;
  height: @input-height-base; // Make inputs at least the height of their button counterpart (base line-height + padding + border)
  padding: @padding-base-vertical @padding-base-horizontal;
  font-size: @font-size-base;
  line-height: @line-height-base;
  color: @gray;
  vertical-align: middle;
  background-color: @input-bg;
  border: 1px solid @input-border;
  border-radius: @input-border-radius;
  .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
  .transition(~"border-color ease-in-out .15s, box-shadow ease-in-out .15s");

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

  // Disabled and read-only inputs
  // 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.
  &[disabled],
  &[readonly],
  fieldset[disabled] & {
    cursor: not-allowed;
    background-color: @input-bg-disabled;
  }

  // Reset height for `textarea`s
  textarea& {
    height: auto;
  }
}


// Form groups
//
// Designed to help with the organization and spacing of vertical forms. For
// horizontal forms, use the predefined grid classes.

.form-group {
  margin-bottom: 15px;
}


// Checkboxes and radios
//
// Indent the labels to position radios/checkboxes as hanging controls.
169
170
171

.radio,
.checkbox {
172
  display: block;
Mark Otto's avatar
Mark Otto committed
173
  min-height: @line-height-computed; // clear the floating input if there is no label text
Mark Otto's avatar
Mark Otto committed
174
175
  margin-top: 10px;
  margin-bottom: 10px;
176
  padding-left: 20px;
Mark Otto's avatar
Mark Otto committed
177
  vertical-align: middle;
Mark Otto's avatar
Mark Otto committed
178
179
180
181
  label {
    display: inline;
    margin-bottom: 0;
    font-weight: normal;
182
    cursor: pointer;
Mark Otto's avatar
Mark Otto committed
183
  }
184
}
185
.radio input[type="radio"],
Mark Otto's avatar
Mark Otto committed
186
187
188
.radio-inline input[type="radio"],
.checkbox input[type="checkbox"],
.checkbox-inline input[type="checkbox"] {
189
  float: left;
190
  margin-left: -20px;
191
}
Mark Otto's avatar
Mark Otto committed
192
193
.radio + .radio,
.checkbox + .checkbox {
Mark Otto's avatar
Mark Otto committed
194
  margin-top: -5px; // Move up sibling radios or checkboxes for tighter spacing
Mark Otto's avatar
Mark Otto committed
195
}
196

197
// Radios and checkboxes on same line
Mark Otto's avatar
Mark Otto committed
198
199
.radio-inline,
.checkbox-inline {
200
  display: inline-block;
Mark Otto's avatar
Mark Otto committed
201
  padding-left: 20px;
202
  margin-bottom: 0;
203
  vertical-align: middle;
Mark Otto's avatar
Mark Otto committed
204
  font-weight: normal;
205
  cursor: pointer;
206
}
Mark Otto's avatar
Mark Otto committed
207
208
209
.radio-inline + .radio-inline,
.checkbox-inline + .checkbox-inline {
  margin-top: 0;
210
  margin-left: 10px; // space out consecutive inline controls
211
212
}

213
214


Mark Otto's avatar
Mark Otto committed
215
216
217
// Form control sizing
//
// Relative text size, padding, and border-radii changes for form controls. For
218
219
220
// horizontal sizing, wrap controls in the predefined grid classes. `<select>`
// element gets special love because it's special, and that's a fact!

221
222
223
224
225
.input-large {
  height: @input-height-large;
  padding: @padding-large-vertical @padding-large-horizontal;
  font-size: @font-size-large;
  border-radius: @border-radius-large;
226
}
227
228
229
230
231
232
233
.input-small {
  height: @input-height-small;
  padding: @padding-small-vertical @padding-small-horizontal;
  font-size: @font-size-small;
  border-radius: @border-radius-small;
}

234
235
236
237
238
239
240
241
242
243
select {
  &.input-large {
    height: @input-height-large;
    line-height: @input-height-large;
  }
  &.input-small {
    height: @input-height-small;
    line-height: @input-height-small;
  }
}
244
245
246
247
248
249
textarea {
  &.input-large,
  &.input-small {
    height: auto;
  }
}
250

Mark Otto's avatar
Mark Otto committed
251

Mark Otto's avatar
Mark Otto committed
252
253
254
// Form control feedback states
//
// Apply contextual and semantic states to individual form controls.
255

256
// Warning
257
.has-warning {
Mark Otto's avatar
Mark Otto committed
258
  .form-control-validation(@state-warning-text, @state-warning-text, @state-warning-bg);
259
260
}
// Error
261
.has-error {
Mark Otto's avatar
Mark Otto committed
262
  .form-control-validation(@state-danger-text, @state-danger-text, @state-danger-bg);
263
264
}
// Success
265
.has-success {
Mark Otto's avatar
Mark Otto committed
266
  .form-control-validation(@state-success-text, @state-success-text, @state-success-bg);
267
}
268
269


Mark Otto's avatar
Mark Otto committed
270
271
272
273
// Help text
//
// Apply to any element you wish to create light text for placement immediately
// below a form control. Use for general help, formatting, or instructional text.
274

275
.help-block {
276
  display: block; // account for any element using help-block
Mark Otto's avatar
Mark Otto committed
277
278
279
  margin-top: 5px;
  margin-bottom: 10px;
  color: lighten(@text-color, 25%); // lighten the text some for contrast
Jacob Thornton's avatar
Jacob Thornton committed
280
}