_input-group.scss 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. // stylelint-disable selector-no-qualifying-type
  2. //
  3. // Base styles
  4. //
  5. .input-group {
  6. position: relative;
  7. display: flex;
  8. flex-wrap: wrap; // For form validation feedback
  9. align-items: stretch;
  10. width: 100%;
  11. > .form-control,
  12. > .form-control-plaintext,
  13. > .custom-select,
  14. > .custom-file {
  15. position: relative; // For focus state's z-index
  16. flex: 1 1 auto;
  17. // Add width 1% and flex-basis auto to ensure that button will not wrap out
  18. // the column. Applies to IE Edge+ and Firefox. Chrome does not require this.
  19. width: 1%;
  20. margin-bottom: 0;
  21. + .form-control,
  22. + .custom-select,
  23. + .custom-file {
  24. margin-left: -$input-border-width;
  25. }
  26. }
  27. // Bring the "active" form control to the top of surrounding elements
  28. > .form-control:focus,
  29. > .custom-select:focus,
  30. > .custom-file .custom-file-input:focus ~ .custom-file-label {
  31. z-index: 3;
  32. }
  33. // Bring the custom file input above the label
  34. > .custom-file .custom-file-input:focus {
  35. z-index: 4;
  36. }
  37. > .form-control,
  38. > .custom-select {
  39. &:not(:last-child) { @include border-right-radius(0); }
  40. &:not(:first-child) { @include border-left-radius(0); }
  41. }
  42. // Custom file inputs have more complex markup, thus requiring different
  43. // border-radius overrides.
  44. > .custom-file {
  45. display: flex;
  46. align-items: center;
  47. &:not(:last-child) .custom-file-label,
  48. &:not(:last-child) .custom-file-label::after { @include border-right-radius(0); }
  49. &:not(:first-child) .custom-file-label { @include border-left-radius(0); }
  50. }
  51. }
  52. // Prepend and append
  53. //
  54. // While it requires one extra layer of HTML for each, dedicated prepend and
  55. // append elements allow us to 1) be less clever, 2) simplify our selectors, and
  56. // 3) support HTML5 form validation.
  57. .input-group-prepend,
  58. .input-group-append {
  59. display: flex;
  60. // Ensure buttons are always above inputs for more visually pleasing borders.
  61. // This isn't needed for `.input-group-text` since it shares the same border-color
  62. // as our inputs.
  63. .btn {
  64. position: relative;
  65. z-index: 2;
  66. &:focus {
  67. z-index: 3;
  68. }
  69. }
  70. .btn + .btn,
  71. .btn + .input-group-text,
  72. .input-group-text + .input-group-text,
  73. .input-group-text + .btn {
  74. margin-left: -$input-border-width;
  75. }
  76. }
  77. .input-group-prepend { margin-right: -$input-border-width; }
  78. .input-group-append { margin-left: -$input-border-width; }
  79. // Textual addons
  80. //
  81. // Serves as a catch-all element for any text or radio/checkbox input you wish
  82. // to prepend or append to an input.
  83. .input-group-text {
  84. display: flex;
  85. align-items: center;
  86. padding: $input-padding-y $input-padding-x;
  87. margin-bottom: 0; // Allow use of <label> elements by overriding our default margin-bottom
  88. @include font-size($input-font-size); // Match inputs
  89. font-weight: $font-weight-normal;
  90. line-height: $input-line-height;
  91. color: $input-group-addon-color;
  92. text-align: center;
  93. white-space: nowrap;
  94. background-color: $input-group-addon-bg;
  95. border: $input-border-width solid $input-group-addon-border-color;
  96. @include border-radius($input-border-radius);
  97. // Nuke default margins from checkboxes and radios to vertically center within.
  98. input[type="radio"],
  99. input[type="checkbox"] {
  100. margin-top: 0;
  101. }
  102. }
  103. // Sizing
  104. //
  105. // Remix the default form control sizing classes into new ones for easier
  106. // manipulation.
  107. .input-group-lg > .form-control:not(textarea),
  108. .input-group-lg > .custom-select {
  109. height: $input-height-lg;
  110. }
  111. .input-group-lg > .form-control,
  112. .input-group-lg > .custom-select,
  113. .input-group-lg > .input-group-prepend > .input-group-text,
  114. .input-group-lg > .input-group-append > .input-group-text,
  115. .input-group-lg > .input-group-prepend > .btn,
  116. .input-group-lg > .input-group-append > .btn {
  117. padding: $input-padding-y-lg $input-padding-x-lg;
  118. @include font-size($input-font-size-lg);
  119. line-height: $input-line-height-lg;
  120. @include border-radius($input-border-radius-lg);
  121. }
  122. .input-group-sm > .form-control:not(textarea),
  123. .input-group-sm > .custom-select {
  124. height: $input-height-sm;
  125. }
  126. .input-group-sm > .form-control,
  127. .input-group-sm > .custom-select,
  128. .input-group-sm > .input-group-prepend > .input-group-text,
  129. .input-group-sm > .input-group-append > .input-group-text,
  130. .input-group-sm > .input-group-prepend > .btn,
  131. .input-group-sm > .input-group-append > .btn {
  132. padding: $input-padding-y-sm $input-padding-x-sm;
  133. @include font-size($input-font-size-sm);
  134. line-height: $input-line-height-sm;
  135. @include border-radius($input-border-radius-sm);
  136. }
  137. .input-group-lg > .custom-select,
  138. .input-group-sm > .custom-select {
  139. padding-right: $custom-select-padding-x + $custom-select-indicator-padding;
  140. }
  141. // Prepend and append rounded corners
  142. //
  143. // These rulesets must come after the sizing ones to properly override sm and lg
  144. // border-radius values when extending. They're more specific than we'd like
  145. // with the `.input-group >` part, but without it, we cannot override the sizing.
  146. .input-group > .input-group-prepend > .btn,
  147. .input-group > .input-group-prepend > .input-group-text,
  148. .input-group > .input-group-append:not(:last-child) > .btn,
  149. .input-group > .input-group-append:not(:last-child) > .input-group-text,
  150. .input-group > .input-group-append:last-child > .btn:not(:last-child):not(.dropdown-toggle),
  151. .input-group > .input-group-append:last-child > .input-group-text:not(:last-child) {
  152. @include border-right-radius(0);
  153. }
  154. .input-group > .input-group-append > .btn,
  155. .input-group > .input-group-append > .input-group-text,
  156. .input-group > .input-group-prepend:not(:first-child) > .btn,
  157. .input-group > .input-group-prepend:not(:first-child) > .input-group-text,
  158. .input-group > .input-group-prepend:first-child > .btn:not(:first-child),
  159. .input-group > .input-group-prepend:first-child > .input-group-text:not(:first-child) {
  160. @include border-left-radius(0);
  161. }