forms.less 8.6 KB

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