forms.less 14 KB

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