_forms.scss 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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: -webkit-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. margin-bottom: 5px;
  30. font-weight: bold;
  31. }
  32. // Normalize form controls
  33. //
  34. // While most of our form styles require extra classes, some basic normalization
  35. // is required to ensure optimum display with or without those classes to better
  36. // address browser inconsistencies.
  37. // Override content-box in Normalize (* isn't specific enough)
  38. input[type="search"] {
  39. @include box-sizing(border-box);
  40. }
  41. // Position radios and checkboxes better
  42. input[type="radio"],
  43. input[type="checkbox"] {
  44. margin: 4px 0 0;
  45. margin-top: 1px \9; /* IE8-9 */
  46. line-height: normal;
  47. }
  48. // Set the height of file controls to match text inputs
  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;
  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. // 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. cursor: not-allowed;
  124. background-color: $input-bg-disabled;
  125. opacity: 1; // iOS fix for unreadable disabled content
  126. }
  127. // [converter] extracted textarea& to textarea.form-control
  128. }
  129. // Reset height for `textarea`s
  130. textarea.form-control {
  131. height: auto;
  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 date input
  143. //
  144. // In Mobile Safari, date inputs require a pixel line-height that matches the
  145. // given height of the input.
  146. input[type="date"] {
  147. line-height: $input-height-base;
  148. }
  149. // Form groups
  150. //
  151. // Designed to help with the organization and spacing of vertical forms. For
  152. // horizontal forms, use the predefined grid classes.
  153. .form-group {
  154. margin-bottom: 15px;
  155. }
  156. // Checkboxes and radios
  157. //
  158. // Indent the labels to position radios/checkboxes as hanging controls.
  159. .radio,
  160. .checkbox {
  161. display: block;
  162. min-height: $line-height-computed; // clear the floating input if there is no label text
  163. margin-top: 10px;
  164. margin-bottom: 10px;
  165. padding-left: 20px;
  166. label {
  167. display: inline;
  168. font-weight: normal;
  169. cursor: pointer;
  170. }
  171. }
  172. .radio input[type="radio"],
  173. .radio-inline input[type="radio"],
  174. .checkbox input[type="checkbox"],
  175. .checkbox-inline input[type="checkbox"] {
  176. float: left;
  177. margin-left: -20px;
  178. }
  179. .radio + .radio,
  180. .checkbox + .checkbox {
  181. margin-top: -5px; // Move up sibling radios or checkboxes for tighter spacing
  182. }
  183. // Radios and checkboxes on same line
  184. .radio-inline,
  185. .checkbox-inline {
  186. display: inline-block;
  187. padding-left: 20px;
  188. margin-bottom: 0;
  189. vertical-align: middle;
  190. font-weight: normal;
  191. cursor: pointer;
  192. }
  193. .radio-inline + .radio-inline,
  194. .checkbox-inline + .checkbox-inline {
  195. margin-top: 0;
  196. margin-left: 10px; // space out consecutive inline controls
  197. }
  198. // Apply same disabled cursor tweak as for inputs
  199. //
  200. // Note: Neither radios nor checkboxes can be readonly.
  201. input[type="radio"],
  202. input[type="checkbox"],
  203. .radio,
  204. .radio-inline,
  205. .checkbox,
  206. .checkbox-inline {
  207. &[disabled],
  208. fieldset[disabled] & {
  209. cursor: not-allowed;
  210. }
  211. }
  212. // Form control sizing
  213. //
  214. // Build on `.form-control` with modifier classes to decrease or increase the
  215. // height and font-size of form controls.
  216. @include input-size('.input-sm', $input-height-small, $padding-small-vertical, $padding-small-horizontal, $font-size-small, $line-height-small, $border-radius-small);
  217. @include input-size('.input-lg', $input-height-large, $padding-large-vertical, $padding-large-horizontal, $font-size-large, $line-height-large, $border-radius-large);
  218. // Form control feedback states
  219. //
  220. // Apply contextual and semantic states to individual form controls.
  221. .has-feedback {
  222. // Enable absolute positioning
  223. position: relative;
  224. // Ensure icons don't overlap text
  225. .form-control {
  226. padding-right: ($input-height-base * 1.25);
  227. }
  228. // Feedback icon (requires .glyphicon classes)
  229. .form-control-feedback {
  230. position: absolute;
  231. top: ($line-height-computed + 5); // Height of the `label` and its margin
  232. right: 0;
  233. display: block;
  234. width: $input-height-base;
  235. height: $input-height-base;
  236. line-height: $input-height-base;
  237. text-align: center;
  238. }
  239. }
  240. // Feedback states
  241. .has-success {
  242. @include form-control-validation($state-success-text, $state-success-text, $state-success-bg);
  243. }
  244. .has-warning {
  245. @include form-control-validation($state-warning-text, $state-warning-text, $state-warning-bg);
  246. }
  247. .has-error {
  248. @include form-control-validation($state-danger-text, $state-danger-text, $state-danger-bg);
  249. }
  250. // Static form control text
  251. //
  252. // Apply class to a `p` element to make any string of text align with labels in
  253. // a horizontal form layout.
  254. .form-control-static {
  255. margin-bottom: 0; // Remove default margin from `p`
  256. }
  257. // Help text
  258. //
  259. // Apply to any element you wish to create light text for placement immediately
  260. // below a form control. Use for general help, formatting, or instructional text.
  261. .help-block {
  262. display: block; // account for any element using help-block
  263. margin-top: 5px;
  264. margin-bottom: 10px;
  265. color: lighten($text-color, 25%); // lighten the text some for contrast
  266. }
  267. // Inline forms
  268. //
  269. // Make forms appear inline(-block) by adding the `.form-inline` class. Inline
  270. // forms begin stacked on extra small (mobile) devices and then go inline when
  271. // viewports reach <768px.
  272. //
  273. // Requires wrapping inputs and labels with `.form-group` for proper display of
  274. // default HTML form controls and our custom form controls (e.g., input groups).
  275. //
  276. // Heads up! This is mixin-ed into `.navbar-form` in navbars.less.
  277. .form-inline {
  278. // Kick in the inline
  279. @media (min-width: $screen-sm-min) {
  280. // Inline-block all the things for "inline"
  281. .form-group {
  282. display: inline-block;
  283. margin-bottom: 0;
  284. vertical-align: middle;
  285. }
  286. // In navbar-form, allow folks to *not* use `.form-group`
  287. .form-control {
  288. display: inline-block;
  289. width: auto; // Prevent labels from stacking above inputs in `.form-group`
  290. vertical-align: middle;
  291. }
  292. // Input groups need that 100% width though
  293. .input-group > .form-control {
  294. width: 100%;
  295. }
  296. .control-label {
  297. margin-bottom: 0;
  298. vertical-align: middle;
  299. }
  300. // Remove default margin on radios/checkboxes that were used for stacking, and
  301. // then undo the floating of radios and checkboxes to match (which also avoids
  302. // a bug in WebKit: https://github.com/twbs/bootstrap/issues/1969).
  303. .radio,
  304. .checkbox {
  305. display: inline-block;
  306. margin-top: 0;
  307. margin-bottom: 0;
  308. padding-left: 0;
  309. vertical-align: middle;
  310. }
  311. .radio input[type="radio"],
  312. .checkbox input[type="checkbox"] {
  313. float: none;
  314. margin-left: 0;
  315. }
  316. // Validation states
  317. //
  318. // Reposition the icon because it's now within a grid column and columns have
  319. // `position: relative;` on them. Also accounts for the grid gutter padding.
  320. .has-feedback .form-control-feedback {
  321. top: 0;
  322. }
  323. }
  324. }
  325. // Horizontal forms
  326. //
  327. // Horizontal forms are built on grid classes and allow you to create forms with
  328. // labels on the left and inputs on the right.
  329. .form-horizontal {
  330. // Consistent vertical alignment of labels, radios, and checkboxes
  331. .control-label,
  332. .radio,
  333. .checkbox,
  334. .radio-inline,
  335. .checkbox-inline {
  336. margin-top: 0;
  337. margin-bottom: 0;
  338. padding-top: ($padding-base-vertical + 1); // Default padding plus a border
  339. }
  340. // Account for padding we're adding to ensure the alignment and of help text
  341. // and other content below items
  342. .radio,
  343. .checkbox {
  344. min-height: ($line-height-computed + ($padding-base-vertical + 1));
  345. }
  346. // Make form groups behave like rows
  347. .form-group {
  348. @include make-row();
  349. }
  350. .form-control-static {
  351. padding-top: ($padding-base-vertical + 1);
  352. }
  353. // Only right align form labels here when the columns stop stacking
  354. @media (min-width: $screen-sm-min) {
  355. .control-label {
  356. text-align: right;
  357. }
  358. }
  359. // Validation states
  360. //
  361. // Reposition the icon because it's now within a grid column and columns have
  362. // `position: relative;` on them. Also accounts for the grid gutter padding.
  363. .has-feedback .form-control-feedback {
  364. top: 0;
  365. right: ($grid-gutter-width / 2);
  366. }
  367. }