_forms.scss 8.8 KB

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