_forms.less 8.8 KB

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