forms.less 8.3 KB

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