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.

612 lines
15 KiB

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