forms.less 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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;
  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
  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.
  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. }
  155. input[type="date"].input-sm,
  156. input[type="time"].input-sm,
  157. input[type="datetime-local"].input-sm,
  158. input[type="month"].input-sm {
  159. line-height: @input-height-small;
  160. }
  161. input[type="date"].input-lg,
  162. input[type="time"].input-lg,
  163. input[type="datetime-local"].input-lg,
  164. input[type="month"].input-lg {
  165. line-height: @input-height-large;
  166. }
  167. }
  168. // Form groups
  169. //
  170. // Designed to help with the organization and spacing of vertical forms. For
  171. // horizontal forms, use the predefined grid classes.
  172. .form-group {
  173. margin-bottom: 15px;
  174. }
  175. // Checkboxes and radios
  176. //
  177. // Indent the labels to position radios/checkboxes as hanging controls.
  178. .radio,
  179. .checkbox {
  180. position: relative;
  181. display: block;
  182. margin-top: 10px;
  183. margin-bottom: 10px;
  184. label {
  185. min-height: @line-height-computed; // Ensure the input doesn't jump when there is no text
  186. padding-left: 20px;
  187. margin-bottom: 0;
  188. font-weight: normal;
  189. cursor: pointer;
  190. }
  191. }
  192. .radio input[type="radio"],
  193. .radio-inline input[type="radio"],
  194. .checkbox input[type="checkbox"],
  195. .checkbox-inline input[type="checkbox"] {
  196. position: absolute;
  197. margin-left: -20px;
  198. margin-top: 4px \9;
  199. }
  200. .radio + .radio,
  201. .checkbox + .checkbox {
  202. margin-top: -5px; // Move up sibling radios or checkboxes for tighter spacing
  203. }
  204. // Radios and checkboxes on same line
  205. .radio-inline,
  206. .checkbox-inline {
  207. display: inline-block;
  208. padding-left: 20px;
  209. margin-bottom: 0;
  210. vertical-align: middle;
  211. font-weight: normal;
  212. cursor: pointer;
  213. }
  214. .radio-inline + .radio-inline,
  215. .checkbox-inline + .checkbox-inline {
  216. margin-top: 0;
  217. margin-left: 10px; // space out consecutive inline controls
  218. }
  219. // Apply same disabled cursor tweak as for inputs
  220. // Some special care is needed because <label>s don't inherit their parent's `cursor`.
  221. //
  222. // Note: Neither radios nor checkboxes can be readonly.
  223. input[type="radio"],
  224. input[type="checkbox"] {
  225. &[disabled],
  226. &.disabled,
  227. fieldset[disabled] & {
  228. cursor: @cursor-disabled;
  229. }
  230. }
  231. // These classes are used directly on <label>s
  232. .radio-inline,
  233. .checkbox-inline {
  234. &.disabled,
  235. fieldset[disabled] & {
  236. cursor: @cursor-disabled;
  237. }
  238. }
  239. // These classes are used on elements with <label> descendants
  240. .radio,
  241. .checkbox {
  242. &.disabled,
  243. fieldset[disabled] & {
  244. label {
  245. cursor: @cursor-disabled;
  246. }
  247. }
  248. }
  249. // Static form control text
  250. //
  251. // Apply class to a `p` element to make any string of text align with labels in
  252. // a horizontal form layout.
  253. .form-control-static {
  254. // Size it appropriately next to real form controls
  255. padding-top: (@padding-base-vertical + 1);
  256. padding-bottom: (@padding-base-vertical + 1);
  257. // Remove default margin from `p`
  258. margin-bottom: 0;
  259. &.input-lg,
  260. &.input-sm {
  261. padding-left: 0;
  262. padding-right: 0;
  263. }
  264. }
  265. // Form control sizing
  266. //
  267. // Build on `.form-control` with modifier classes to decrease or increase the
  268. // height and font-size of form controls.
  269. .input-sm,
  270. .form-group-sm .form-control {
  271. .input-size(@input-height-small; @padding-small-vertical; @padding-small-horizontal; @font-size-small; @line-height-small; @input-border-radius-small);
  272. }
  273. .input-lg,
  274. .form-group-lg .form-control {
  275. .input-size(@input-height-large; @padding-large-vertical; @padding-large-horizontal; @font-size-large; @line-height-large; @input-border-radius-large);
  276. }
  277. // Form control feedback states
  278. //
  279. // Apply contextual and semantic states to individual form controls.
  280. .has-feedback {
  281. // Enable absolute positioning
  282. position: relative;
  283. // Ensure icons don't overlap text
  284. .form-control {
  285. padding-right: (@input-height-base * 1.25);
  286. }
  287. }
  288. // Feedback icon (requires .glyphicon classes)
  289. .form-control-feedback {
  290. position: absolute;
  291. top: 0;
  292. right: 0;
  293. z-index: 2; // Ensure icon is above input groups
  294. display: block;
  295. width: @input-height-base;
  296. height: @input-height-base;
  297. line-height: @input-height-base;
  298. text-align: center;
  299. pointer-events: none;
  300. }
  301. .input-lg + .form-control-feedback {
  302. width: @input-height-large;
  303. height: @input-height-large;
  304. line-height: @input-height-large;
  305. }
  306. .input-sm + .form-control-feedback {
  307. width: @input-height-small;
  308. height: @input-height-small;
  309. line-height: @input-height-small;
  310. }
  311. // Feedback states
  312. .has-success {
  313. .form-control-validation(@state-success-text; @state-success-text; @state-success-bg);
  314. }
  315. .has-warning {
  316. .form-control-validation(@state-warning-text; @state-warning-text; @state-warning-bg);
  317. }
  318. .has-error {
  319. .form-control-validation(@state-danger-text; @state-danger-text; @state-danger-bg);
  320. }
  321. // Reposition feedback icon if input has visible label above
  322. .has-feedback label {
  323. & ~ .form-control-feedback {
  324. top: (@line-height-computed + 5); // Height of the `label` and its margin
  325. }
  326. &.sr-only ~ .form-control-feedback {
  327. top: 0;
  328. }
  329. }
  330. // Help text
  331. //
  332. // Apply to any element you wish to create light text for placement immediately
  333. // below a form control. Use for general help, formatting, or instructional text.
  334. .help-block {
  335. display: block; // account for any element using help-block
  336. margin-top: 5px;
  337. margin-bottom: 10px;
  338. color: lighten(@text-color, 25%); // lighten the text some for contrast
  339. }
  340. // Inline forms
  341. //
  342. // Make forms appear inline(-block) by adding the `.form-inline` class. Inline
  343. // forms begin stacked on extra small (mobile) devices and then go inline when
  344. // viewports reach <768px.
  345. //
  346. // Requires wrapping inputs and labels with `.form-group` for proper display of
  347. // default HTML form controls and our custom form controls (e.g., input groups).
  348. //
  349. // Heads up! This is mixin-ed into `.navbar-form` in navbars.less.
  350. .form-inline {
  351. // Kick in the inline
  352. @media (min-width: @screen-sm-min) {
  353. // Inline-block all the things for "inline"
  354. .form-group {
  355. display: inline-block;
  356. margin-bottom: 0;
  357. vertical-align: middle;
  358. }
  359. // In navbar-form, allow folks to *not* use `.form-group`
  360. .form-control {
  361. display: inline-block;
  362. width: auto; // Prevent labels from stacking above inputs in `.form-group`
  363. vertical-align: middle;
  364. }
  365. // Make static controls behave like regular ones
  366. .form-control-static {
  367. display: inline-block;
  368. }
  369. .input-group {
  370. display: inline-table;
  371. vertical-align: middle;
  372. .input-group-addon,
  373. .input-group-btn,
  374. .form-control {
  375. width: auto;
  376. }
  377. }
  378. // Input groups need that 100% width though
  379. .input-group > .form-control {
  380. width: 100%;
  381. }
  382. .control-label {
  383. margin-bottom: 0;
  384. vertical-align: middle;
  385. }
  386. // Remove default margin on radios/checkboxes that were used for stacking, and
  387. // then undo the floating of radios and checkboxes to match (which also avoids
  388. // a bug in WebKit: https://github.com/twbs/bootstrap/issues/1969).
  389. .radio,
  390. .checkbox {
  391. display: inline-block;
  392. margin-top: 0;
  393. margin-bottom: 0;
  394. vertical-align: middle;
  395. label {
  396. padding-left: 0;
  397. }
  398. }
  399. .radio input[type="radio"],
  400. .checkbox input[type="checkbox"] {
  401. position: relative;
  402. margin-left: 0;
  403. }
  404. // Re-override the feedback icon.
  405. .has-feedback .form-control-feedback {
  406. top: 0;
  407. }
  408. }
  409. }
  410. // Horizontal forms
  411. //
  412. // Horizontal forms are built on grid classes and allow you to create forms with
  413. // labels on the left and inputs on the right.
  414. .form-horizontal {
  415. // Consistent vertical alignment of radios and checkboxes
  416. //
  417. // Labels also get some reset styles, but that is scoped to a media query below.
  418. .radio,
  419. .checkbox,
  420. .radio-inline,
  421. .checkbox-inline {
  422. margin-top: 0;
  423. margin-bottom: 0;
  424. padding-top: (@padding-base-vertical + 1); // Default padding plus a border
  425. }
  426. // Account for padding we're adding to ensure the alignment and of help text
  427. // and other content below items
  428. .radio,
  429. .checkbox {
  430. min-height: (@line-height-computed + (@padding-base-vertical + 1));
  431. }
  432. // Make form groups behave like rows
  433. .form-group {
  434. .make-row();
  435. }
  436. // Reset spacing and right align labels, but scope to media queries so that
  437. // labels on narrow viewports stack the same as a default form example.
  438. @media (min-width: @screen-sm-min) {
  439. .control-label {
  440. text-align: right;
  441. margin-bottom: 0;
  442. padding-top: (@padding-base-vertical + 1); // Default padding plus a border
  443. }
  444. }
  445. // Validation states
  446. //
  447. // Reposition the icon because it's now within a grid column and columns have
  448. // `position: relative;` on them. Also accounts for the grid gutter padding.
  449. .has-feedback .form-control-feedback {
  450. right: (@grid-gutter-width / 2);
  451. }
  452. // Form group sizes
  453. //
  454. // Quick utility class for applying `.input-lg` and `.input-sm` styles to the
  455. // inputs and labels within a `.form-group`.
  456. .form-group-lg {
  457. @media (min-width: @screen-sm-min) {
  458. .control-label {
  459. padding-top: ((@padding-large-vertical * @line-height-large) + 1);
  460. }
  461. }
  462. }
  463. .form-group-sm {
  464. @media (min-width: @screen-sm-min) {
  465. .control-label {
  466. padding-top: (@padding-small-vertical + 1);
  467. }
  468. }
  469. }
  470. }