_forms.scss 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. // stylelint-disable selector-no-qualifying-type
  2. //
  3. // Textual form controls
  4. //
  5. .form-control {
  6. display: block;
  7. width: 100%;
  8. height: $input-height;
  9. padding: $input-padding-y $input-padding-x;
  10. font-family: $input-font-family;
  11. @include font-size($input-font-size);
  12. font-weight: $input-font-weight;
  13. line-height: $input-line-height;
  14. color: $input-color;
  15. background-color: $input-bg;
  16. background-clip: padding-box;
  17. border: $input-border-width solid $input-border-color;
  18. // Note: This has no effect on <select>s in some browsers, due to the limited stylability of `<select>`s in CSS.
  19. @include border-radius($input-border-radius, 0);
  20. @include box-shadow($input-box-shadow);
  21. @include transition($input-transition);
  22. // Unstyle the caret on `<select>`s in IE10+.
  23. &::-ms-expand {
  24. background-color: transparent;
  25. border: 0;
  26. }
  27. // Customize the `:focus` state to imitate native WebKit styles.
  28. @include form-control-focus();
  29. // Placeholder
  30. &::placeholder {
  31. color: $input-placeholder-color;
  32. // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526.
  33. opacity: 1;
  34. }
  35. // Disabled and read-only inputs
  36. //
  37. // HTML5 says that controls under a fieldset > legend:first-child won't be
  38. // disabled if the fieldset is disabled. Due to implementation difficulty, we
  39. // don't honor that edge case; we style them as disabled anyway.
  40. &:disabled,
  41. &[readonly] {
  42. background-color: $input-disabled-bg;
  43. // iOS fix for unreadable disabled content; see https://github.com/twbs/bootstrap/issues/11655.
  44. opacity: 1;
  45. }
  46. }
  47. select.form-control {
  48. &:focus::-ms-value {
  49. // Suppress the nested default white text on blue background highlight given to
  50. // the selected option text when the (still closed) <select> receives focus
  51. // in IE and (under certain conditions) Edge, as it looks bad and cannot be made to
  52. // match the appearance of the native widget.
  53. // See https://github.com/twbs/bootstrap/issues/19398.
  54. color: $input-color;
  55. background-color: $input-bg;
  56. }
  57. }
  58. // Make file inputs better match text inputs by forcing them to new lines.
  59. .form-control-file,
  60. .form-control-range {
  61. display: block;
  62. width: 100%;
  63. }
  64. //
  65. // Labels
  66. //
  67. // For use with horizontal and inline forms, when you need the label (or legend)
  68. // text to align with the form controls.
  69. .col-form-label {
  70. padding-top: calc(#{$input-padding-y} + #{$input-border-width});
  71. padding-bottom: calc(#{$input-padding-y} + #{$input-border-width});
  72. margin-bottom: 0; // Override the `<label>/<legend>` default
  73. @include font-size(inherit); // Override the `<legend>` default
  74. line-height: $input-line-height;
  75. }
  76. .col-form-label-lg {
  77. padding-top: calc(#{$input-padding-y-lg} + #{$input-border-width});
  78. padding-bottom: calc(#{$input-padding-y-lg} + #{$input-border-width});
  79. @include font-size($input-font-size-lg);
  80. line-height: $input-line-height-lg;
  81. }
  82. .col-form-label-sm {
  83. padding-top: calc(#{$input-padding-y-sm} + #{$input-border-width});
  84. padding-bottom: calc(#{$input-padding-y-sm} + #{$input-border-width});
  85. @include font-size($input-font-size-sm);
  86. line-height: $input-line-height-sm;
  87. }
  88. // Readonly controls as plain text
  89. //
  90. // Apply class to a readonly input to make it appear like regular plain
  91. // text (without any border, background color, focus indicator)
  92. .form-control-plaintext {
  93. display: block;
  94. width: 100%;
  95. padding-top: $input-padding-y;
  96. padding-bottom: $input-padding-y;
  97. margin-bottom: 0; // match inputs if this class comes on inputs with default margins
  98. line-height: $input-line-height;
  99. color: $input-plaintext-color;
  100. background-color: transparent;
  101. border: solid transparent;
  102. border-width: $input-border-width 0;
  103. &.form-control-sm,
  104. &.form-control-lg {
  105. padding-right: 0;
  106. padding-left: 0;
  107. }
  108. }
  109. // Form control sizing
  110. //
  111. // Build on `.form-control` with modifier classes to decrease or increase the
  112. // height and font-size of form controls.
  113. //
  114. // Repeated in `_input_group.scss` to avoid Sass extend issues.
  115. .form-control-sm {
  116. height: $input-height-sm;
  117. padding: $input-padding-y-sm $input-padding-x-sm;
  118. @include font-size($input-font-size-sm);
  119. line-height: $input-line-height-sm;
  120. @include border-radius($input-border-radius-sm);
  121. }
  122. .form-control-lg {
  123. height: $input-height-lg;
  124. padding: $input-padding-y-lg $input-padding-x-lg;
  125. @include font-size($input-font-size-lg);
  126. line-height: $input-line-height-lg;
  127. @include border-radius($input-border-radius-lg);
  128. }
  129. // stylelint-disable-next-line no-duplicate-selectors
  130. select.form-control {
  131. &[size],
  132. &[multiple] {
  133. height: auto;
  134. }
  135. }
  136. textarea.form-control {
  137. height: auto;
  138. }
  139. // Form groups
  140. //
  141. // Designed to help with the organization and spacing of vertical forms. For
  142. // horizontal forms, use the predefined grid classes.
  143. .form-group {
  144. margin-bottom: $form-group-margin-bottom;
  145. }
  146. .form-text {
  147. display: block;
  148. margin-top: $form-text-margin-top;
  149. }
  150. // Form grid
  151. //
  152. // Special replacement for our grid system's `.row` for tighter form layouts.
  153. .form-row {
  154. display: flex;
  155. flex-wrap: wrap;
  156. margin-right: -$form-grid-gutter-width / 2;
  157. margin-left: -$form-grid-gutter-width / 2;
  158. > .col,
  159. > [class*="col-"] {
  160. padding-right: $form-grid-gutter-width / 2;
  161. padding-left: $form-grid-gutter-width / 2;
  162. }
  163. }
  164. // Checkboxes and radios
  165. //
  166. // Indent the labels to position radios/checkboxes as hanging controls.
  167. .form-check {
  168. position: relative;
  169. display: block;
  170. padding-left: $form-check-input-gutter;
  171. }
  172. .form-check-input {
  173. position: absolute;
  174. margin-top: $form-check-input-margin-y;
  175. margin-left: -$form-check-input-gutter;
  176. &:disabled ~ .form-check-label {
  177. color: $text-muted;
  178. }
  179. }
  180. .form-check-label {
  181. margin-bottom: 0; // Override default `<label>` bottom margin
  182. }
  183. .form-check-inline {
  184. display: inline-flex;
  185. align-items: center;
  186. padding-left: 0; // Override base .form-check
  187. margin-right: $form-check-inline-margin-x;
  188. // Undo .form-check-input defaults and add some `margin-right`.
  189. .form-check-input {
  190. position: static;
  191. margin-top: 0;
  192. margin-right: $form-check-inline-input-margin-x;
  193. margin-left: 0;
  194. }
  195. }
  196. // Form validation
  197. //
  198. // Provide feedback to users when form field values are valid or invalid. Works
  199. // primarily for client-side validation via scoped `:invalid` and `:valid`
  200. // pseudo-classes but also includes `.is-invalid` and `.is-valid` classes for
  201. // server side validation.
  202. @each $state, $data in $form-validation-states {
  203. @include form-validation-state($state, map-get($data, color), map-get($data, icon));
  204. }
  205. // Inline forms
  206. //
  207. // Make forms appear inline(-block) by adding the `.form-inline` class. Inline
  208. // forms begin stacked on extra small (mobile) devices and then go inline when
  209. // viewports reach <768px.
  210. //
  211. // Requires wrapping inputs and labels with `.form-group` for proper display of
  212. // default HTML form controls and our custom form controls (e.g., input groups).
  213. .form-inline {
  214. display: flex;
  215. flex-flow: row wrap;
  216. align-items: center; // Prevent shorter elements from growing to same height as others (e.g., small buttons growing to normal sized button height)
  217. // Because we use flex, the initial sizing of checkboxes is collapsed and
  218. // doesn't occupy the full-width (which is what we want for xs grid tier),
  219. // so we force that here.
  220. .form-check {
  221. width: 100%;
  222. }
  223. // Kick in the inline
  224. @include media-breakpoint-up(sm) {
  225. label {
  226. display: flex;
  227. align-items: center;
  228. justify-content: center;
  229. margin-bottom: 0;
  230. }
  231. // Inline-block all the things for "inline"
  232. .form-group {
  233. display: flex;
  234. flex: 0 0 auto;
  235. flex-flow: row wrap;
  236. align-items: center;
  237. margin-bottom: 0;
  238. }
  239. // Allow folks to *not* use `.form-group`
  240. .form-control {
  241. display: inline-block;
  242. width: auto; // Prevent labels from stacking above inputs in `.form-group`
  243. vertical-align: middle;
  244. }
  245. // Make static controls behave like regular ones
  246. .form-control-plaintext {
  247. display: inline-block;
  248. }
  249. .input-group,
  250. .custom-select {
  251. width: auto;
  252. }
  253. // Remove default margin on radios/checkboxes that were used for stacking, and
  254. // then undo the floating of radios and checkboxes to match.
  255. .form-check {
  256. display: flex;
  257. align-items: center;
  258. justify-content: center;
  259. width: auto;
  260. padding-left: 0;
  261. }
  262. .form-check-input {
  263. position: relative;
  264. flex-shrink: 0;
  265. margin-top: 0;
  266. margin-right: $form-check-input-margin-x;
  267. margin-left: 0;
  268. }
  269. .custom-control {
  270. align-items: center;
  271. justify-content: center;
  272. }
  273. .custom-control-label {
  274. margin-bottom: 0;
  275. }
  276. }
  277. }