_forms.scss 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. // scss-lint:disable QualifyingElement
  2. //
  3. // Textual form controls
  4. //
  5. .form-control {
  6. display: block;
  7. width: 100%;
  8. // // Make inputs at least the height of their button counterpart (base line-height + padding + border)
  9. // height: $input-height;
  10. padding: $input-padding-y $input-padding-x;
  11. font-size: $font-size-base;
  12. line-height: $input-line-height;
  13. color: $input-color;
  14. background-color: $input-bg;
  15. // Reset unusual Firefox-on-Android default style; see https://github.com/necolas/normalize.css/issues/214.
  16. background-image: none;
  17. background-clip: padding-box;
  18. border: $input-btn-border-width solid $input-border-color;
  19. // Note: This has no effect on <select>s in some browsers, due to the limited stylability of `<select>`s in CSS.
  20. @if $enable-rounded {
  21. // Manually use the if/else instead of the mixin to account for iOS override
  22. border-radius: $input-border-radius;
  23. } @else {
  24. // Otherwise undo the iOS default
  25. border-radius: 0;
  26. }
  27. @include box-shadow($input-box-shadow);
  28. @include transition(border-color ease-in-out .15s, box-shadow ease-in-out .15s);
  29. // Unstyle the caret on `<select>`s in IE10+.
  30. &::-ms-expand {
  31. background-color: transparent;
  32. border: 0;
  33. }
  34. // Customize the `:focus` state to imitate native WebKit styles.
  35. @include form-control-focus();
  36. // Placeholder
  37. &::placeholder {
  38. color: $input-color-placeholder;
  39. // Override Firefox's unusual default opacity; see https://github.com/twbs/bootstrap/pull/11526.
  40. opacity: 1;
  41. }
  42. // Disabled and read-only inputs
  43. //
  44. // HTML5 says that controls under a fieldset > legend:first-child won't be
  45. // disabled if the fieldset is disabled. Due to implementation difficulty, we
  46. // don't honor that edge case; we style them as disabled anyway.
  47. &:disabled,
  48. &[readonly] {
  49. background-color: $input-bg-disabled;
  50. // iOS fix for unreadable disabled content; see https://github.com/twbs/bootstrap/issues/11655.
  51. opacity: 1;
  52. }
  53. &:disabled {
  54. cursor: $cursor-disabled;
  55. }
  56. }
  57. select.form-control {
  58. &:not([size]):not([multiple]) {
  59. $select-border-width: ($border-width * 2);
  60. height: calc(#{$input-height} - #{$select-border-width});
  61. }
  62. &:focus::-ms-value {
  63. // Suppress the nested default white text on blue background highlight given to
  64. // the selected option text when the (still closed) <select> receives focus
  65. // in IE and (under certain conditions) Edge, as it looks bad and cannot be made to
  66. // match the appearance of the native widget.
  67. // See https://github.com/twbs/bootstrap/issues/19398.
  68. color: $input-color;
  69. background-color: $input-bg;
  70. }
  71. }
  72. // Make file inputs better match text inputs by forcing them to new lines.
  73. .form-control-file,
  74. .form-control-range {
  75. display: block;
  76. }
  77. //
  78. // Labels
  79. //
  80. // For use with horizontal and inline forms, when you need the label text to
  81. // align with the form controls.
  82. .col-form-label {
  83. padding-top: $input-padding-y;
  84. padding-bottom: $input-padding-y;
  85. margin-bottom: 0; // Override the `<label>` default
  86. }
  87. .col-form-label-lg {
  88. padding-top: $input-padding-y-lg;
  89. padding-bottom: $input-padding-y-lg;
  90. font-size: $font-size-lg;
  91. }
  92. .col-form-label-sm {
  93. padding-top: $input-padding-y-sm;
  94. padding-bottom: $input-padding-y-sm;
  95. font-size: $font-size-sm;
  96. }
  97. //
  98. // Legends
  99. //
  100. // For use with horizontal and inline forms, when you need the legend text to
  101. // be the same size as regular labels, and to align with the form controls.
  102. .col-form-legend {
  103. padding-top: $input-padding-y;
  104. padding-bottom: $input-padding-y;
  105. margin-bottom: 0;
  106. font-size: $font-size-base;
  107. }
  108. // Static form control text
  109. //
  110. // Apply class to an element to make any string of text align with labels in a
  111. // horizontal form layout.
  112. .form-control-static {
  113. padding-top: $input-padding-y;
  114. padding-bottom: $input-padding-y;
  115. line-height: $input-line-height;
  116. border: solid transparent;
  117. border-width: 1px 0;
  118. &.form-control-sm,
  119. &.form-control-lg {
  120. padding-right: 0;
  121. padding-left: 0;
  122. }
  123. }
  124. // Form control sizing
  125. //
  126. // Build on `.form-control` with modifier classes to decrease or increase the
  127. // height and font-size of form controls.
  128. //
  129. // The `.form-group-* form-control` variations are sadly duplicated to avoid the
  130. // issue documented in https://github.com/twbs/bootstrap/issues/15074.
  131. .form-control-sm {
  132. padding: $input-padding-y-sm $input-padding-x-sm;
  133. font-size: $font-size-sm;
  134. @include border-radius($input-border-radius-sm);
  135. }
  136. select.form-control-sm {
  137. &:not([size]):not([multiple]) {
  138. height: $input-height-sm;
  139. }
  140. }
  141. .form-control-lg {
  142. padding: $input-padding-y-lg $input-padding-x-lg;
  143. font-size: $font-size-lg;
  144. @include border-radius($input-border-radius-lg);
  145. }
  146. select.form-control-lg {
  147. &:not([size]):not([multiple]) {
  148. height: $input-height-lg;
  149. }
  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: ($spacer * .25);
  161. }
  162. // Checkboxes and radios
  163. //
  164. // Indent the labels to position radios/checkboxes as hanging controls.
  165. .form-check {
  166. position: relative;
  167. display: block;
  168. margin-bottom: ($spacer * .75);
  169. // Move up sibling radios or checkboxes for tighter spacing
  170. + .form-check {
  171. margin-top: -.25rem;
  172. }
  173. &.disabled {
  174. .form-check-label {
  175. color: $text-muted;
  176. cursor: $cursor-disabled;
  177. }
  178. }
  179. }
  180. .form-check-label {
  181. padding-left: 1.25rem;
  182. margin-bottom: 0; // Override default `<label>` bottom margin
  183. cursor: pointer;
  184. }
  185. .form-check-input {
  186. position: absolute;
  187. margin-top: .25rem;
  188. margin-left: -1.25rem;
  189. &:only-child {
  190. position: static;
  191. }
  192. }
  193. // Radios and checkboxes on same line
  194. .form-check-inline {
  195. position: relative;
  196. display: inline-block;
  197. padding-left: 1.25rem;
  198. margin-bottom: 0; // Override default `<label>` bottom margin
  199. vertical-align: middle;
  200. cursor: pointer;
  201. + .form-check-inline {
  202. margin-left: .75rem;
  203. }
  204. &.disabled {
  205. color: $text-muted;
  206. cursor: $cursor-disabled;
  207. }
  208. }
  209. // Form control feedback states
  210. //
  211. // Apply contextual and semantic states to individual form controls.
  212. .form-control-feedback {
  213. margin-top: ($spacer * .25);
  214. }
  215. .form-control-success,
  216. .form-control-warning,
  217. .form-control-danger {
  218. padding-right: ($input-padding-x * 3);
  219. background-repeat: no-repeat;
  220. background-position: center right ($input-height / 4);
  221. background-size: ($input-height / 2) ($input-height / 2);
  222. }
  223. // Form validation states
  224. .has-success {
  225. @include form-control-validation($brand-success);
  226. .form-control-success {
  227. background-image: $form-icon-success;
  228. }
  229. }
  230. .has-warning {
  231. @include form-control-validation($brand-warning);
  232. .form-control-warning {
  233. background-image: $form-icon-warning;
  234. }
  235. }
  236. .has-danger {
  237. @include form-control-validation($brand-danger);
  238. .form-control-danger {
  239. background-image: $form-icon-danger;
  240. }
  241. }
  242. // Inline forms
  243. //
  244. // Make forms appear inline(-block) by adding the `.form-inline` class. Inline
  245. // forms begin stacked on extra small (mobile) devices and then go inline when
  246. // viewports reach <768px.
  247. //
  248. // Requires wrapping inputs and labels with `.form-group` for proper display of
  249. // default HTML form controls and our custom form controls (e.g., input groups).
  250. .form-inline {
  251. // Kick in the inline
  252. @include media-breakpoint-up(sm) {
  253. // Inline-block all the things for "inline"
  254. .form-group {
  255. display: inline-block;
  256. margin-bottom: 0;
  257. vertical-align: middle;
  258. }
  259. // Allow folks to *not* use `.form-group`
  260. .form-control {
  261. display: inline-block;
  262. width: auto; // Prevent labels from stacking above inputs in `.form-group`
  263. vertical-align: middle;
  264. }
  265. // Make static controls behave like regular ones
  266. .form-control-static {
  267. display: inline-block;
  268. }
  269. .input-group {
  270. display: inline-table;
  271. width: auto;
  272. vertical-align: middle;
  273. .input-group-addon,
  274. .input-group-btn,
  275. .form-control {
  276. width: auto;
  277. }
  278. }
  279. // Input groups need that 100% width though
  280. .input-group > .form-control {
  281. width: 100%;
  282. }
  283. .form-control-label {
  284. margin-bottom: 0;
  285. vertical-align: middle;
  286. }
  287. // Remove default margin on radios/checkboxes that were used for stacking, and
  288. // then undo the floating of radios and checkboxes to match.
  289. .form-check {
  290. display: inline-block;
  291. margin-top: 0;
  292. margin-bottom: 0;
  293. vertical-align: middle;
  294. }
  295. .form-check-label {
  296. padding-left: 0;
  297. }
  298. .form-check-input {
  299. position: relative;
  300. margin-left: 0;
  301. }
  302. // Re-override the feedback icon.
  303. .has-feedback .form-control-feedback {
  304. top: 0;
  305. }
  306. }
  307. }