You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

438 lines
11 KiB

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