forms.less 9.0 KB

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