_forms.scss 16 KB

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