_input-group.scss 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //
  2. // Base styles
  3. //
  4. .input-group {
  5. position: relative;
  6. @if $enable-flex {
  7. display: flex;
  8. } @else {
  9. display: table;
  10. // Prevent input groups from inheriting border styles from table cells when
  11. // placed within a table.
  12. border-collapse: separate;
  13. }
  14. .form-control {
  15. // Ensure that the input is always above the *appended* addon button for
  16. // proper border colors.
  17. position: relative;
  18. z-index: 2;
  19. // Bring the "active" form control to the front
  20. @include hover-focus-active {
  21. z-index: 3;
  22. }
  23. @if $enable-flex {
  24. flex: 1;
  25. } @else {
  26. // IE9 fubars the placeholder attribute in text inputs and the arrows on
  27. // select elements in input groups. To fix it, we float the input. Details:
  28. // https://github.com/twbs/bootstrap/issues/11561#issuecomment-28936855
  29. float: left;
  30. width: 100%;
  31. }
  32. margin-bottom: 0;
  33. }
  34. }
  35. .input-group-addon,
  36. .input-group-btn,
  37. .input-group .form-control {
  38. @if $enable-flex {
  39. // do nothing
  40. } @else {
  41. display: table-cell;
  42. }
  43. &:not(:first-child):not(:last-child) {
  44. @include border-radius(0);
  45. }
  46. }
  47. .input-group-addon,
  48. .input-group-btn {
  49. @if $enable-flex {
  50. // do nothing
  51. } @else {
  52. width: 1%;
  53. }
  54. white-space: nowrap;
  55. vertical-align: middle; // Match the inputs
  56. }
  57. // Sizing options
  58. //
  59. // Remix the default form control sizing classes into new ones for easier
  60. // manipulation.
  61. .input-group-lg > .form-control,
  62. .input-group-lg > .input-group-addon,
  63. .input-group-lg > .input-group-btn > .btn {
  64. @extend .form-control-lg;
  65. }
  66. .input-group-sm > .form-control,
  67. .input-group-sm > .input-group-addon,
  68. .input-group-sm > .input-group-btn > .btn {
  69. @extend .form-control-sm;
  70. }
  71. //
  72. // Text input groups
  73. //
  74. .input-group-addon {
  75. padding: $input-padding-y $input-padding-x;
  76. font-size: $font-size-base;
  77. font-weight: normal;
  78. line-height: 1;
  79. color: $input-color;
  80. text-align: center;
  81. background-color: $input-group-addon-bg;
  82. border: $input-btn-border-width solid $input-group-addon-border-color;
  83. @include border-radius($border-radius);
  84. // Sizing
  85. &.form-control-sm {
  86. padding: $input-padding-y-sm $input-padding-x-sm;
  87. font-size: $font-size-sm;
  88. @include border-radius($border-radius-sm);
  89. }
  90. &.form-control-lg {
  91. padding: $input-padding-y-lg $input-padding-x-lg;
  92. font-size: $font-size-lg;
  93. @include border-radius($border-radius-lg);
  94. }
  95. // Nuke default margins from checkboxes and radios to vertically center within.
  96. input[type="radio"],
  97. input[type="checkbox"] {
  98. margin-top: 0;
  99. }
  100. }
  101. //
  102. // Reset rounded corners
  103. //
  104. .input-group .form-control:first-child,
  105. .input-group-addon:first-child,
  106. .input-group-btn:first-child > .btn,
  107. .input-group-btn:first-child > .btn-group > .btn,
  108. .input-group-btn:first-child > .dropdown-toggle,
  109. .input-group-btn:last-child > .btn:not(:last-child):not(.dropdown-toggle),
  110. .input-group-btn:last-child > .btn-group:not(:last-child) > .btn {
  111. @include border-right-radius(0);
  112. }
  113. .input-group-addon:first-child {
  114. border-right: 0;
  115. }
  116. .input-group .form-control:last-child,
  117. .input-group-addon:last-child,
  118. .input-group-btn:last-child > .btn,
  119. .input-group-btn:last-child > .btn-group > .btn,
  120. .input-group-btn:last-child > .dropdown-toggle,
  121. .input-group-btn:first-child > .btn:not(:first-child),
  122. .input-group-btn:first-child > .btn-group:not(:first-child) > .btn {
  123. @include border-left-radius(0);
  124. }
  125. .input-group-addon:last-child {
  126. border-left: 0;
  127. }
  128. //
  129. // Button input groups
  130. //
  131. .input-group-btn {
  132. position: relative;
  133. // Jankily prevent input button groups from wrapping with `white-space` and
  134. // `font-size` in combination with `inline-block` on buttons.
  135. font-size: 0;
  136. white-space: nowrap;
  137. // Negative margin for spacing, position for bringing hovered/focused/actived
  138. // element above the siblings.
  139. > .btn {
  140. position: relative;
  141. + .btn {
  142. margin-left: (-$input-btn-border-width);
  143. }
  144. // Bring the "active" button to the front
  145. @include hover-focus-active {
  146. z-index: 3;
  147. }
  148. }
  149. // Negative margin to only have a single, shared border between the two
  150. &:first-child {
  151. > .btn,
  152. > .btn-group {
  153. margin-right: (-$input-btn-border-width);
  154. }
  155. }
  156. &:last-child {
  157. > .btn,
  158. > .btn-group {
  159. z-index: 2;
  160. margin-left: (-$input-btn-border-width);
  161. // Because specificity
  162. @include hover-focus-active {
  163. z-index: 3;
  164. }
  165. }
  166. }
  167. }