static/less/forms.less
author stetrabby <info@trabucchi.de>
Fri, 20 Dec 2013 22:30:44 +0100
changeset 53 3416f82943ea
permissions -rwxr-xr-x
less initial added
info@53
     1
//
info@53
     2
// Forms
info@53
     3
// --------------------------------------------------
info@53
     4
info@53
     5
info@53
     6
// Normalize non-controls
info@53
     7
//
info@53
     8
// Restyle and baseline non-control form elements.
info@53
     9
info@53
    10
fieldset {
info@53
    11
  padding: 0;
info@53
    12
  margin: 0;
info@53
    13
  border: 0;
info@53
    14
}
info@53
    15
info@53
    16
legend {
info@53
    17
  display: block;
info@53
    18
  width: 100%;
info@53
    19
  padding: 0;
info@53
    20
  margin-bottom: @line-height-computed;
info@53
    21
  font-size: (@font-size-base * 1.5);
info@53
    22
  line-height: inherit;
info@53
    23
  color: @legend-color;
info@53
    24
  border: 0;
info@53
    25
  border-bottom: 1px solid @legend-border-color;
info@53
    26
}
info@53
    27
info@53
    28
label {
info@53
    29
  display: inline-block;
info@53
    30
  margin-bottom: 5px;
info@53
    31
  font-weight: bold;
info@53
    32
}
info@53
    33
info@53
    34
info@53
    35
// Normalize form controls
info@53
    36
info@53
    37
// Override content-box in Normalize (* isn't specific enough)
info@53
    38
input[type="search"] {
info@53
    39
  .box-sizing(border-box);
info@53
    40
}
info@53
    41
info@53
    42
// Position radios and checkboxes better
info@53
    43
input[type="radio"],
info@53
    44
input[type="checkbox"] {
info@53
    45
  margin: 4px 0 0;
info@53
    46
  margin-top: 1px \9; /* IE8-9 */
info@53
    47
  line-height: normal;
info@53
    48
}
info@53
    49
info@53
    50
// Set the height of select and file controls to match text inputs
info@53
    51
input[type="file"] {
info@53
    52
  display: block;
info@53
    53
}
info@53
    54
info@53
    55
// Make multiple select elements height not fixed
info@53
    56
select[multiple],
info@53
    57
select[size] {
info@53
    58
  height: auto;
info@53
    59
}
info@53
    60
info@53
    61
// Fix optgroup Firefox bug per https://github.com/twbs/bootstrap/issues/7611
info@53
    62
select optgroup {
info@53
    63
  font-size: inherit;
info@53
    64
  font-style: inherit;
info@53
    65
  font-family: inherit;
info@53
    66
}
info@53
    67
info@53
    68
// Focus for select, file, radio, and checkbox
info@53
    69
input[type="file"]:focus,
info@53
    70
input[type="radio"]:focus,
info@53
    71
input[type="checkbox"]:focus {
info@53
    72
  .tab-focus();
info@53
    73
}
info@53
    74
info@53
    75
// Fix for Chrome number input
info@53
    76
// Setting certain font-sizes causes the `I` bar to appear on hover of the bottom increment button.
info@53
    77
// See https://github.com/twbs/bootstrap/issues/8350 for more.
info@53
    78
input[type="number"] {
info@53
    79
  &::-webkit-outer-spin-button,
info@53
    80
  &::-webkit-inner-spin-button {
info@53
    81
    height: auto;
info@53
    82
  }
info@53
    83
}
info@53
    84
info@53
    85
// Adjust output element
info@53
    86
output {
info@53
    87
  display: block;
info@53
    88
  padding-top: (@padding-base-vertical + 1);
info@53
    89
  font-size: @font-size-base;
info@53
    90
  line-height: @line-height-base;
info@53
    91
  color: @input-color;
info@53
    92
  vertical-align: middle;
info@53
    93
}
info@53
    94
info@53
    95
info@53
    96
// Common form controls
info@53
    97
//
info@53
    98
// Shared size and type resets for form controls. Apply `.form-control` to any
info@53
    99
// of the following form controls:
info@53
   100
//
info@53
   101
// select
info@53
   102
// textarea
info@53
   103
// input[type="text"]
info@53
   104
// input[type="password"]
info@53
   105
// input[type="datetime"]
info@53
   106
// input[type="datetime-local"]
info@53
   107
// input[type="date"]
info@53
   108
// input[type="month"]
info@53
   109
// input[type="time"]
info@53
   110
// input[type="week"]
info@53
   111
// input[type="number"]
info@53
   112
// input[type="email"]
info@53
   113
// input[type="url"]
info@53
   114
// input[type="search"]
info@53
   115
// input[type="tel"]
info@53
   116
// input[type="color"]
info@53
   117
info@53
   118
.form-control {
info@53
   119
  display: block;
info@53
   120
  width: 100%;
info@53
   121
  height: @input-height-base; // Make inputs at least the height of their button counterpart (base line-height + padding + border)
info@53
   122
  padding: @padding-base-vertical @padding-base-horizontal;
info@53
   123
  font-size: @font-size-base;
info@53
   124
  line-height: @line-height-base;
info@53
   125
  color: @input-color;
info@53
   126
  vertical-align: middle;
info@53
   127
  background-color: @input-bg;
info@53
   128
  background-image: none; // Reset unusual Firefox-on-Android default style; see https://github.com/necolas/normalize.css/issues/214
info@53
   129
  border: 1px solid @input-border;
info@53
   130
  border-radius: @input-border-radius;
info@53
   131
  .box-shadow(inset 0 1px 1px rgba(0,0,0,.075));
info@53
   132
  .transition(~"border-color ease-in-out .15s, box-shadow ease-in-out .15s");
info@53
   133
info@53
   134
  // Customize the `:focus` state to imitate native WebKit styles.
info@53
   135
  .form-control-focus();
info@53
   136
info@53
   137
  // Placeholder
info@53
   138
  //
info@53
   139
  // Placeholder text gets special styles because when browsers invalidate entire
info@53
   140
  // lines if it doesn't understand a selector/
info@53
   141
  .placeholder();
info@53
   142
info@53
   143
  // Disabled and read-only inputs
info@53
   144
  // Note: HTML5 says that controls under a fieldset > legend:first-child won't
info@53
   145
  // be disabled if the fieldset is disabled. Due to implementation difficulty,
info@53
   146
  // we don't honor that edge case; we style them as disabled anyway.
info@53
   147
  &[disabled],
info@53
   148
  &[readonly],
info@53
   149
  fieldset[disabled] & {
info@53
   150
    cursor: not-allowed;
info@53
   151
    background-color: @input-bg-disabled;
info@53
   152
  }
info@53
   153
info@53
   154
  // Reset height for `textarea`s
info@53
   155
  textarea& {
info@53
   156
    height: auto;
info@53
   157
  }
info@53
   158
}
info@53
   159
info@53
   160
info@53
   161
// Form groups
info@53
   162
//
info@53
   163
// Designed to help with the organization and spacing of vertical forms. For
info@53
   164
// horizontal forms, use the predefined grid classes.
info@53
   165
info@53
   166
.form-group {
info@53
   167
  margin-bottom: 15px;
info@53
   168
}
info@53
   169
info@53
   170
info@53
   171
// Checkboxes and radios
info@53
   172
//
info@53
   173
// Indent the labels to position radios/checkboxes as hanging controls.
info@53
   174
info@53
   175
.radio,
info@53
   176
.checkbox {
info@53
   177
  display: block;
info@53
   178
  min-height: @line-height-computed; // clear the floating input if there is no label text
info@53
   179
  margin-top: 10px;
info@53
   180
  margin-bottom: 10px;
info@53
   181
  padding-left: 20px;
info@53
   182
  vertical-align: middle;
info@53
   183
  label {
info@53
   184
    display: inline;
info@53
   185
    margin-bottom: 0;
info@53
   186
    font-weight: normal;
info@53
   187
    cursor: pointer;
info@53
   188
  }
info@53
   189
}
info@53
   190
.radio input[type="radio"],
info@53
   191
.radio-inline input[type="radio"],
info@53
   192
.checkbox input[type="checkbox"],
info@53
   193
.checkbox-inline input[type="checkbox"] {
info@53
   194
  float: left;
info@53
   195
  margin-left: -20px;
info@53
   196
}
info@53
   197
.radio + .radio,
info@53
   198
.checkbox + .checkbox {
info@53
   199
  margin-top: -5px; // Move up sibling radios or checkboxes for tighter spacing
info@53
   200
}
info@53
   201
info@53
   202
// Radios and checkboxes on same line
info@53
   203
.radio-inline,
info@53
   204
.checkbox-inline {
info@53
   205
  display: inline-block;
info@53
   206
  padding-left: 20px;
info@53
   207
  margin-bottom: 0;
info@53
   208
  vertical-align: middle;
info@53
   209
  font-weight: normal;
info@53
   210
  cursor: pointer;
info@53
   211
}
info@53
   212
.radio-inline + .radio-inline,
info@53
   213
.checkbox-inline + .checkbox-inline {
info@53
   214
  margin-top: 0;
info@53
   215
  margin-left: 10px; // space out consecutive inline controls
info@53
   216
}
info@53
   217
info@53
   218
// Apply same disabled cursor tweak as for inputs
info@53
   219
//
info@53
   220
// Note: Neither radios nor checkboxes can be readonly.
info@53
   221
input[type="radio"],
info@53
   222
input[type="checkbox"],
info@53
   223
.radio,
info@53
   224
.radio-inline,
info@53
   225
.checkbox,
info@53
   226
.checkbox-inline {
info@53
   227
  &[disabled],
info@53
   228
  fieldset[disabled] & {
info@53
   229
    cursor: not-allowed;
info@53
   230
  }
info@53
   231
}
info@53
   232
info@53
   233
// Form control sizing
info@53
   234
.input-sm {
info@53
   235
  .input-size(@input-height-small; @padding-small-vertical; @padding-small-horizontal; @font-size-small; @line-height-small; @border-radius-small);
info@53
   236
}
info@53
   237
info@53
   238
.input-lg {
info@53
   239
  .input-size(@input-height-large; @padding-large-vertical; @padding-large-horizontal; @font-size-large; @line-height-large; @border-radius-large);
info@53
   240
}
info@53
   241
info@53
   242
info@53
   243
// Form control feedback states
info@53
   244
//
info@53
   245
// Apply contextual and semantic states to individual form controls.
info@53
   246
info@53
   247
// Warning
info@53
   248
.has-warning {
info@53
   249
  .form-control-validation(@state-warning-text; @state-warning-text; @state-warning-bg);
info@53
   250
}
info@53
   251
// Error
info@53
   252
.has-error {
info@53
   253
  .form-control-validation(@state-danger-text; @state-danger-text; @state-danger-bg);
info@53
   254
}
info@53
   255
// Success
info@53
   256
.has-success {
info@53
   257
  .form-control-validation(@state-success-text; @state-success-text; @state-success-bg);
info@53
   258
}
info@53
   259
info@53
   260
info@53
   261
// Static form control text
info@53
   262
//
info@53
   263
// Apply class to a `p` element to make any string of text align with labels in
info@53
   264
// a horizontal form layout.
info@53
   265
info@53
   266
.form-control-static {
info@53
   267
  margin-bottom: 0; // Remove default margin from `p`
info@53
   268
}
info@53
   269
info@53
   270
info@53
   271
// Help text
info@53
   272
//
info@53
   273
// Apply to any element you wish to create light text for placement immediately
info@53
   274
// below a form control. Use for general help, formatting, or instructional text.
info@53
   275
info@53
   276
.help-block {
info@53
   277
  display: block; // account for any element using help-block
info@53
   278
  margin-top: 5px;
info@53
   279
  margin-bottom: 10px;
info@53
   280
  color: lighten(@text-color, 25%); // lighten the text some for contrast
info@53
   281
}
info@53
   282
info@53
   283
info@53
   284
info@53
   285
// Inline forms
info@53
   286
//
info@53
   287
// Make forms appear inline(-block) by adding the `.form-inline` class. Inline
info@53
   288
// forms begin stacked on extra small (mobile) devices and then go inline when
info@53
   289
// viewports reach <768px.
info@53
   290
//
info@53
   291
// Requires wrapping inputs and labels with `.form-group` for proper display of
info@53
   292
// default HTML form controls and our custom form controls (e.g., input groups).
info@53
   293
//
info@53
   294
// Heads up! This is mixin-ed into `.navbar-form` in navbars.less.
info@53
   295
info@53
   296
.form-inline {
info@53
   297
info@53
   298
  // Kick in the inline
info@53
   299
  @media (min-width: @screen-sm) {
info@53
   300
    // Inline-block all the things for "inline"
info@53
   301
    .form-group  {
info@53
   302
      display: inline-block;
info@53
   303
      margin-bottom: 0;
info@53
   304
      vertical-align: middle;
info@53
   305
    }
info@53
   306
info@53
   307
    // In navbar-form, allow folks to *not* use `.form-group`
info@53
   308
    .form-control {
info@53
   309
      display: inline-block;
info@53
   310
    }
info@53
   311
info@53
   312
    // Override `width: 100%;` when not within a `.form-group`
info@53
   313
    select.form-control {
info@53
   314
      width: auto;
info@53
   315
    }
info@53
   316
info@53
   317
    // Remove default margin on radios/checkboxes that were used for stacking, and
info@53
   318
    // then undo the floating of radios and checkboxes to match (which also avoids
info@53
   319
    // a bug in WebKit: https://github.com/twbs/bootstrap/issues/1969).
info@53
   320
    .radio,
info@53
   321
    .checkbox {
info@53
   322
      display: inline-block;
info@53
   323
      margin-top: 0;
info@53
   324
      margin-bottom: 0;
info@53
   325
      padding-left: 0;
info@53
   326
    }
info@53
   327
    .radio input[type="radio"],
info@53
   328
    .checkbox input[type="checkbox"] {
info@53
   329
      float: none;
info@53
   330
      margin-left: 0;
info@53
   331
    }
info@53
   332
  }
info@53
   333
}
info@53
   334
info@53
   335
info@53
   336
// Horizontal forms
info@53
   337
//
info@53
   338
// Horizontal forms are built on grid classes and allow you to create forms with
info@53
   339
// labels on the left and inputs on the right.
info@53
   340
info@53
   341
.form-horizontal {
info@53
   342
info@53
   343
  // Consistent vertical alignment of labels, radios, and checkboxes
info@53
   344
  .control-label,
info@53
   345
  .radio,
info@53
   346
  .checkbox,
info@53
   347
  .radio-inline,
info@53
   348
  .checkbox-inline {
info@53
   349
    margin-top: 0;
info@53
   350
    margin-bottom: 0;
info@53
   351
    padding-top: (@padding-base-vertical + 1); // Default padding plus a border
info@53
   352
  }
info@53
   353
  // Account for padding we're adding to ensure the alignment and of help text
info@53
   354
  // and other content below items
info@53
   355
  .radio,
info@53
   356
  .checkbox {
info@53
   357
    min-height: @line-height-computed + (@padding-base-vertical + 1);
info@53
   358
  }
info@53
   359
info@53
   360
  // Make form groups behave like rows
info@53
   361
  .form-group {
info@53
   362
    .make-row();
info@53
   363
  }
info@53
   364
info@53
   365
  .form-control-static {
info@53
   366
    padding-top: (@padding-base-vertical + 1);
info@53
   367
  }
info@53
   368
info@53
   369
  // Only right align form labels here when the columns stop stacking
info@53
   370
  @media (min-width: @screen-sm-min) {
info@53
   371
    .control-label {
info@53
   372
      text-align: right;
info@53
   373
    }
info@53
   374
  }
info@53
   375
}
Impressum Datenschutzerklärung