_forms.scss 8.6 KB

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