_forms.scss 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. // stylelint-disable selector-no-qualifying-type
  2. //
  3. // Textual form controls
  4. //
  5. .form-control {
  6. display: block;
  7. width: 100%;
  8. padding: $input-padding-y $input-padding-x;
  9. font-size: $font-size-base;
  10. line-height: $input-line-height;
  11. color: $input-color;
  12. background-color: $input-bg;
  13. background-clip: padding-box;
  14. border: $input-border-width solid $input-border-color;
  15. // Note: This has no effect on <select>s in some browsers, due to the limited stylability of `<select>`s in CSS.
  16. @if $enable-rounded {
  17. // Manually use the if/else instead of the mixin to account for iOS override
  18. border-radius: $input-border-radius;
  19. } @else {
  20. // Otherwise undo the iOS default
  21. border-radius: 0;
  22. }
  23. @include box-shadow($input-box-shadow);
  24. @include transition($input-transition);
  25. // Unstyle the caret on `<select>`s in IE10+.
  26. &::-ms-expand {
  27. background-color: transparent;
  28. border: 0;
  29. }
  30. // Customize the `:focus` state to imitate native WebKit styles.
  31. @include form-control-focus();
  32. // Placeholder
  33. &::placeholder {
  34. color: $input-placeholder-color;
  35. // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526.
  36. opacity: 1;
  37. }
  38. // Disabled and read-only inputs
  39. //
  40. // HTML5 says that controls under a fieldset > legend:first-child won't be
  41. // disabled if the fieldset is disabled. Due to implementation difficulty, we
  42. // don't honor that edge case; we style them as disabled anyway.
  43. &:disabled,
  44. &[readonly] {
  45. background-color: $input-disabled-bg;
  46. // iOS fix for unreadable disabled content; see https://github.com/twbs/bootstrap/issues/11655.
  47. opacity: 1;
  48. }
  49. }
  50. select.form-control {
  51. &:not([size]):not([multiple]) {
  52. height: $input-height;
  53. }
  54. &:focus::-ms-value {
  55. // Suppress the nested default white text on blue background highlight given to
  56. // the selected option text when the (still closed) <select> receives focus
  57. // in IE and (under certain conditions) Edge, as it looks bad and cannot be made to
  58. // match the appearance of the native widget.
  59. // See https://github.com/twbs/bootstrap/issues/19398.
  60. color: $input-color;
  61. background-color: $input-bg;
  62. }
  63. }
  64. // Make file inputs better match text inputs by forcing them to new lines.
  65. .form-control-file,
  66. .form-control-range {
  67. display: block;
  68. width: 100%;
  69. }
  70. //
  71. // Labels
  72. //
  73. // For use with horizontal and inline forms, when you need the label (or legend)
  74. // text to align with the form controls.
  75. .col-form-label {
  76. padding-top: calc(#{$input-padding-y} + #{$input-border-width});
  77. padding-bottom: calc(#{$input-padding-y} + #{$input-border-width});
  78. margin-bottom: 0; // Override the `<label>/<legend>` default
  79. font-size: inherit; // Override the `<legend>` default
  80. line-height: $input-line-height;
  81. }
  82. .col-form-label-lg {
  83. padding-top: calc(#{$input-padding-y-lg} + #{$input-border-width});
  84. padding-bottom: calc(#{$input-padding-y-lg} + #{$input-border-width});
  85. font-size: $font-size-lg;
  86. line-height: $input-line-height-lg;
  87. }
  88. .col-form-label-sm {
  89. padding-top: calc(#{$input-padding-y-sm} + #{$input-border-width});
  90. padding-bottom: calc(#{$input-padding-y-sm} + #{$input-border-width});
  91. font-size: $font-size-sm;
  92. line-height: $input-line-height-sm;
  93. }
  94. // Readonly controls as plain text
  95. //
  96. // Apply class to a readonly input to make it appear like regular plain
  97. // text (without any border, background color, focus indicator)
  98. .form-control-plaintext {
  99. display: block;
  100. width: 100%;
  101. padding-top: $input-padding-y;
  102. padding-bottom: $input-padding-y;
  103. margin-bottom: 0; // match inputs if this class comes on inputs with default margins
  104. line-height: $input-line-height;
  105. color: $input-plaintext-color;
  106. background-color: transparent;
  107. border: solid transparent;
  108. border-width: $input-border-width 0;
  109. &.form-control-sm,
  110. &.form-control-lg {
  111. padding-right: 0;
  112. padding-left: 0;
  113. }
  114. }
  115. // Form control sizing
  116. //
  117. // Build on `.form-control` with modifier classes to decrease or increase the
  118. // height and font-size of form controls.
  119. //
  120. // The `.form-group-* form-control` variations are sadly duplicated to avoid the
  121. // issue documented in https://github.com/twbs/bootstrap/issues/15074.
  122. .form-control-sm {
  123. padding: $input-padding-y-sm $input-padding-x-sm;
  124. font-size: $font-size-sm;
  125. line-height: $input-line-height-sm;
  126. @include border-radius($input-border-radius-sm);
  127. }
  128. select.form-control-sm {
  129. &:not([size]):not([multiple]) {
  130. height: $input-height-sm;
  131. }
  132. }
  133. .form-control-lg {
  134. padding: $input-padding-y-lg $input-padding-x-lg;
  135. font-size: $font-size-lg;
  136. line-height: $input-line-height-lg;
  137. @include border-radius($input-border-radius-lg);
  138. }
  139. select.form-control-lg {
  140. &:not([size]):not([multiple]) {
  141. height: $input-height-lg;
  142. }
  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: -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. }