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.

607 lines
15 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: 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. max-width: 100%; // Force IE8 to wrap long content (see https://github.com/twbs/bootstrap/issues/13141)
  30. margin-bottom: 5px;
  31. font-weight: bold;
  32. }
  33. // Normalize form controls
  34. //
  35. // While most of our form styles require extra classes, some basic normalization
  36. // is required to ensure optimum display with or without those classes to better
  37. // address browser inconsistencies.
  38. // Override content-box in Normalize (* isn't specific enough)
  39. input[type="search"] {
  40. .box-sizing(border-box);
  41. }
  42. // Position radios and checkboxes better
  43. input[type="radio"],
  44. input[type="checkbox"] {
  45. margin: 4px 0 0;
  46. margin-top: 1px \9; // IE8-9
  47. line-height: normal;
  48. }
  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; // Note: This has no effect on <select>s in some browsers, due to the limited stylability of <select>s in CSS.
  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. background-color: @input-bg-disabled;
  124. opacity: 1; // iOS fix for unreadable disabled content; see https://github.com/twbs/bootstrap/issues/11655
  125. }
  126. &[disabled],
  127. fieldset[disabled] & {
  128. cursor: @cursor-disabled;
  129. }
  130. // Reset height for `textarea`s
  131. textarea& {
  132. height: auto;
  133. }
  134. }
  135. // Search inputs in iOS
  136. //
  137. // This overrides the extra rounded corners on search inputs in iOS so that our
  138. // `.form-control` class can properly style them. Note that this cannot simply
  139. // be added to `.form-control` as it's not specific enough. For details, see
  140. // https://github.com/twbs/bootstrap/issues/11586.
  141. input[type="search"] {
  142. -webkit-appearance: none;
  143. }
  144. // Special styles for iOS temporal inputs
  145. //
  146. // In Mobile Safari, setting `display: block` on temporal inputs causes the
  147. // text within the input to become vertically misaligned. As a workaround, we
  148. // set a pixel line-height that matches the given height of the input, but only
  149. // for Safari. See https://bugs.webkit.org/show_bug.cgi?id=139848
  150. //
  151. // Note that as of 8.3, iOS doesn't support `datetime` or `week`.
  152. @media screen and (-webkit-min-device-pixel-ratio: 0) {
  153. input[type="date"],
  154. input[type="time"],
  155. input[type="datetime-local"],
  156. input[type="month"] {
  157. &.form-control {
  158. line-height: @input-height-base;
  159. }
  160. &.input-sm,
  161. .input-group-sm & {
  162. line-height: @input-height-small;
  163. }
  164. &.input-lg,
  165. .input-group-lg & {
  166. line-height: @input-height-large;
  167. }
  168. }
  169. }
  170. // Form groups
  171. //
  172. // Designed to help with the organization and spacing of vertical forms. For
  173. // horizontal forms, use the predefined grid classes.
  174. .form-group {
  175. margin-bottom: @form-group-margin-bottom;
  176. }
  177. // Checkboxes and radios
  178. //
  179. // Indent the labels to position radios/checkboxes as hanging controls.
  180. .radio,
  181. .checkbox {
  182. position: relative;
  183. display: block;
  184. margin-top: 10px;
  185. margin-bottom: 10px;
  186. label {
  187. min-height: @line-height-computed; // Ensure the input doesn't jump when there is no text
  188. padding-left: 20px;
  189. margin-bottom: 0;
  190. font-weight: normal;
  191. cursor: pointer;
  192. }
  193. }
  194. .radio input[type="radio"],
  195. .radio-inline input[type="radio"],
  196. .checkbox input[type="checkbox"],
  197. .checkbox-inline input[type="checkbox"] {
  198. position: absolute;
  199. margin-left: -20px;
  200. margin-top: 4px \9;
  201. }
  202. .radio + .radio,
  203. .checkbox + .checkbox {
  204. margin-top: -5px; // Move up sibling radios or checkboxes for tighter spacing
  205. }
  206. // Radios and checkboxes on same line
  207. .radio-inline,
  208. .checkbox-inline {
  209. position: relative;
  210. display: inline-block;
  211. padding-left: 20px;
  212. margin-bottom: 0;
  213. vertical-align: middle;
  214. font-weight: normal;
  215. cursor: pointer;
  216. }
  217. .radio-inline + .radio-inline,
  218. .checkbox-inline + .checkbox-inline {
  219. margin-top: 0;
  220. margin-left: 10px; // space out consecutive inline controls
  221. }
  222. // Apply same disabled cursor tweak as for inputs
  223. // Some special care is needed because <label>s don't inherit their parent's `cursor`.
  224. //
  225. // Note: Neither radios nor checkboxes can be readonly.
  226. input[type="radio"],
  227. input[type="checkbox"] {
  228. &[disabled],
  229. &.disabled,
  230. fieldset[disabled] & {
  231. cursor: @cursor-disabled;
  232. }
  233. }
  234. // These classes are used directly on <label>s
  235. .radio-inline,
  236. .checkbox-inline {
  237. &.disabled,
  238. fieldset[disabled] & {
  239. cursor: @cursor-disabled;
  240. }
  241. }
  242. // These classes are used on elements with <label> descendants
  243. .radio,
  244. .checkbox {
  245. &.disabled,
  246. fieldset[disabled] & {
  247. label {
  248. cursor: @cursor-disabled;
  249. }
  250. }
  251. }
  252. // Static form control text
  253. //
  254. // Apply class to a `p` element to make any string of text align with labels in
  255. // a horizontal form layout.
  256. .form-control-static {
  257. // Size it appropriately next to real form controls
  258. padding-top: (@padding-base-vertical + 1);
  259. padding-bottom: (@padding-base-vertical + 1);
  260. // Remove default margin from `p`
  261. margin-bottom: 0;
  262. min-height: (@line-height-computed + @font-size-base);
  263. &.input-lg,
  264. &.input-sm {
  265. padding-left: 0;
  266. padding-right: 0;
  267. }
  268. }
  269. // Form control sizing
  270. //
  271. // Build on `.form-control` with modifier classes to decrease or increase the
  272. // height and font-size of form controls.
  273. //
  274. // The `.form-group-* form-control` variations are sadly duplicated to avoid the
  275. // issue documented in https://github.com/twbs/bootstrap/issues/15074.
  276. .input-sm {
  277. .input-size(@input-height-small; @padding-small-vertical; @padding-small-horizontal; @font-size-small; @line-height-small; @input-border-radius-small);
  278. }
  279. .form-group-sm {
  280. .form-control {
  281. height: @input-height-small;
  282. padding: @padding-small-vertical @padding-small-horizontal;
  283. font-size: @font-size-small;
  284. line-height: @line-height-small;
  285. border-radius: @input-border-radius-small;
  286. }
  287. select.form-control {
  288. height: @input-height-small;
  289. line-height: @input-height-small;
  290. }
  291. textarea.form-control,
  292. select[multiple].form-control {
  293. height: auto;
  294. }
  295. .form-control-static {
  296. height: @input-height-small;
  297. min-height: (@line-height-computed + @font-size-small);
  298. padding: (@padding-small-vertical + 1) @padding-small-horizontal;
  299. font-size: @font-size-small;
  300. line-height: @line-height-small;
  301. }
  302. }
  303. .input-lg {
  304. .input-size(@input-height-large; @padding-large-vertical; @padding-large-horizontal; @font-size-large; @line-height-large; @input-border-radius-large);
  305. }
  306. .form-group-lg {
  307. .form-control {
  308. height: @input-height-large;
  309. padding: @padding-large-vertical @padding-large-horizontal;
  310. font-size: @font-size-large;
  311. line-height: @line-height-large;
  312. border-radius: @input-border-radius-large;
  313. }
  314. select.form-control {
  315. height: @input-height-large;
  316. line-height: @input-height-large;
  317. }
  318. textarea.form-control,
  319. select[multiple].form-control {
  320. height: auto;
  321. }
  322. .form-control-static {
  323. height: @input-height-large;
  324. min-height: (@line-height-computed + @font-size-large);
  325. padding: (@padding-large-vertical + 1) @padding-large-horizontal;
  326. font-size: @font-size-large;
  327. line-height: @line-height-large;
  328. }
  329. }
  330. // Form control feedback states
  331. //
  332. // Apply contextual and semantic states to individual form controls.
  333. .has-feedback {
  334. // Enable absolute positioning
  335. position: relative;
  336. // Ensure icons don't overlap text
  337. .form-control {
  338. padding-right: (@input-height-base * 1.25);
  339. }
  340. }
  341. // Feedback icon (requires .glyphicon classes)
  342. .form-control-feedback {
  343. position: absolute;
  344. top: 0;
  345. right: 0;
  346. z-index: 2; // Ensure icon is above input groups
  347. display: block;
  348. width: @input-height-base;
  349. height: @input-height-base;
  350. line-height: @input-height-base;
  351. text-align: center;
  352. pointer-events: none;
  353. }
  354. .input-lg + .form-control-feedback,
  355. .input-group-lg + .form-control-feedback,
  356. .form-group-lg .form-control + .form-control-feedback {
  357. width: @input-height-large;
  358. height: @input-height-large;
  359. line-height: @input-height-large;
  360. }
  361. .input-sm + .form-control-feedback,
  362. .input-group-sm + .form-control-feedback,
  363. .form-group-sm .form-control + .form-control-feedback {
  364. width: @input-height-small;
  365. height: @input-height-small;
  366. line-height: @input-height-small;
  367. }
  368. // Feedback states
  369. .has-success {
  370. .form-control-validation(@state-success-text; @state-success-text; @state-success-bg);
  371. }
  372. .has-warning {
  373. .form-control-validation(@state-warning-text; @state-warning-text; @state-warning-bg);
  374. }
  375. .has-error {
  376. .form-control-validation(@state-danger-text; @state-danger-text; @state-danger-bg);
  377. }
  378. // Reposition feedback icon if input has visible label above
  379. .has-feedback label {
  380. & ~ .form-control-feedback {
  381. top: (@line-height-computed + 5); // Height of the `label` and its margin
  382. }
  383. &.sr-only ~ .form-control-feedback {
  384. top: 0;
  385. }
  386. }
  387. // Help text
  388. //
  389. // Apply to any element you wish to create light text for placement immediately
  390. // below a form control. Use for general help, formatting, or instructional text.
  391. .help-block {
  392. display: block; // account for any element using help-block
  393. margin-top: 5px;
  394. margin-bottom: 10px;
  395. color: lighten(@text-color, 25%); // lighten the text some for contrast
  396. }
  397. // Inline forms
  398. //
  399. // Make forms appear inline(-block) by adding the `.form-inline` class. Inline
  400. // forms begin stacked on extra small (mobile) devices and then go inline when
  401. // viewports reach <768px.
  402. //
  403. // Requires wrapping inputs and labels with `.form-group` for proper display of
  404. // default HTML form controls and our custom form controls (e.g., input groups).
  405. //
  406. // Heads up! This is mixin-ed into `.navbar-form` in navbars.less.
  407. .form-inline {
  408. // Kick in the inline
  409. @media (min-width: @screen-sm-min) {
  410. // Inline-block all the things for "inline"
  411. .form-group {
  412. display: inline-block;
  413. margin-bottom: 0;
  414. vertical-align: middle;
  415. }
  416. // In navbar-form, allow folks to *not* use `.form-group`
  417. .form-control {
  418. display: inline-block;
  419. width: auto; // Prevent labels from stacking above inputs in `.form-group`
  420. vertical-align: middle;
  421. }
  422. // Make static controls behave like regular ones
  423. .form-control-static {
  424. display: inline-block;
  425. }
  426. .input-group {
  427. display: inline-table;
  428. vertical-align: middle;
  429. .input-group-addon,
  430. .input-group-btn,
  431. .form-control {
  432. width: auto;
  433. }
  434. }
  435. // Input groups need that 100% width though
  436. .input-group > .form-control {
  437. width: 100%;
  438. }
  439. .control-label {
  440. margin-bottom: 0;
  441. vertical-align: middle;
  442. }
  443. // Remove default margin on radios/checkboxes that were used for stacking, and
  444. // then undo the floating of radios and checkboxes to match.
  445. .radio,
  446. .checkbox {
  447. display: inline-block;
  448. margin-top: 0;
  449. margin-bottom: 0;
  450. vertical-align: middle;
  451. label {
  452. padding-left: 0;
  453. }
  454. }
  455. .radio input[type="radio"],
  456. .checkbox input[type="checkbox"] {
  457. position: relative;
  458. margin-left: 0;
  459. }
  460. // Re-override the feedback icon.
  461. .has-feedback .form-control-feedback {
  462. top: 0;
  463. }
  464. }
  465. }
  466. // Horizontal forms
  467. //
  468. // Horizontal forms are built on grid classes and allow you to create forms with
  469. // labels on the left and inputs on the right.
  470. .form-horizontal {
  471. // Consistent vertical alignment of radios and checkboxes
  472. //
  473. // Labels also get some reset styles, but that is scoped to a media query below.
  474. .radio,
  475. .checkbox,
  476. .radio-inline,
  477. .checkbox-inline {
  478. margin-top: 0;
  479. margin-bottom: 0;
  480. padding-top: (@padding-base-vertical + 1); // Default padding plus a border
  481. }
  482. // Account for padding we're adding to ensure the alignment and of help text
  483. // and other content below items
  484. .radio,
  485. .checkbox {
  486. min-height: (@line-height-computed + (@padding-base-vertical + 1));
  487. }
  488. // Make form groups behave like rows
  489. .form-group {
  490. .make-row();
  491. }
  492. // Reset spacing and right align labels, but scope to media queries so that
  493. // labels on narrow viewports stack the same as a default form example.
  494. @media (min-width: @screen-sm-min) {
  495. .control-label {
  496. text-align: right;
  497. margin-bottom: 0;
  498. padding-top: (@padding-base-vertical + 1); // Default padding plus a border
  499. }
  500. }
  501. // Validation states
  502. //
  503. // Reposition the icon because it's now within a grid column and columns have
  504. // `position: relative;` on them. Also accounts for the grid gutter padding.
  505. .has-feedback .form-control-feedback {
  506. right: floor((@grid-gutter-width / 2));
  507. }
  508. // Form group sizes
  509. //
  510. // Quick utility class for applying `.input-lg` and `.input-sm` styles to the
  511. // inputs and labels within a `.form-group`.
  512. .form-group-lg {
  513. @media (min-width: @screen-sm-min) {
  514. .control-label {
  515. padding-top: ((@padding-large-vertical * @line-height-large) + 1);
  516. font-size: @font-size-large;
  517. }
  518. }
  519. }
  520. .form-group-sm {
  521. @media (min-width: @screen-sm-min) {
  522. .control-label {
  523. padding-top: (@padding-small-vertical + 1);
  524. font-size: @font-size-small;
  525. }
  526. }
  527. }
  528. }