_input-group.scss 5.09 KB
Newer Older
1
//
Mark Otto's avatar
Mark Otto committed
2
// Base styles
3
4
//

Mark Otto's avatar
Mark Otto committed
5
.input-group {
6
  position: relative;
7
  width: 100%;
8
9
10
11
12
13
14
15
16

  @if $enable-flex {
    display: flex;
  } @else {
    display: table;
    // Prevent input groups from inheriting border styles from table cells when
    // placed within a table.
    border-collapse: separate;
  }
Mark Otto's avatar
Mark Otto committed
17
18

  .form-control {
19
20
21
22
    // Ensure that the input is always above the *appended* addon button for
    // proper border colors.
    position: relative;
    z-index: 2;
Chris Rebert's avatar
Chris Rebert committed
23
24
25
26
    // Bring the "active" form control to the front
    @include hover-focus-active {
      z-index: 3;
    }
27

28
    @if $enable-flex {
29
30
31
32
      flex: 1 1 auto;
      // Add width 1% and flex-basis auto to ensure that button will not wrap out
      // the column. Applies to IE Edge+ and Firefox. Chrome do not require this.
      width: 1%;
33
34
35
36
37
38
39
    } @else {
      // IE9 fubars the placeholder attribute in text inputs and the arrows on
      // select elements in input groups. To fix it, we float the input. Details:
      // https://github.com/twbs/bootstrap/issues/11561#issuecomment-28936855
      float: left;
      width: 100%;
    }
Mark Otto's avatar
Mark Otto committed
40
41
42
43
    margin-bottom: 0;
  }
}

44
45
46
.input-group-addon,
.input-group-btn,
.input-group .form-control {
47
48
49
50
  @if $enable-flex {
    // Vertically centers the content of the addons within the input group
    display: flex;
    flex-direction: column;
Mark Otto's avatar
Mark Otto committed
51
    justify-content: center;
52
  } @else {
53
54
    display: table-cell;
  }
55
56
57
58
59
60
61
62

  &:not(:first-child):not(:last-child) {
    @include border-radius(0);
  }
}

.input-group-addon,
.input-group-btn {
63
  @if not $enable-flex {
64
65
    width: 1%;
  }
66
67
68
69
70
  white-space: nowrap;
  vertical-align: middle; // Match the inputs
}


71
72
73
74
75
76
// Sizing options
//
// Remix the default form control sizing classes into new ones for easier
// manipulation.

.input-group-lg > .form-control,
77
.input-group-lg > .input-group-addon,
Nick Schonning's avatar
Nick Schonning committed
78
.input-group-lg > .input-group-btn > .btn {
79
  @extend .form-control-lg;
Nick Schonning's avatar
Nick Schonning committed
80
}
81
.input-group-sm > .form-control,
82
.input-group-sm > .input-group-addon,
Nick Schonning's avatar
Nick Schonning committed
83
.input-group-sm > .input-group-btn > .btn {
84
  @extend .form-control-sm;
Nick Schonning's avatar
Nick Schonning committed
85
}
86
87


88
//
Mark Otto's avatar
Mark Otto committed
89
// Text input groups
90
91
//

Mark Otto's avatar
Mark Otto committed
92
.input-group-addon {
93
  padding: $input-padding-y $input-padding-x;
94
  margin-bottom: 0; // Allow use of <label> elements by overriding our default margin-bottom
Mark Otto's avatar
Mark Otto committed
95
  font-size: $font-size-base;
96
  font-weight: $font-weight-normal;
97
  line-height: $input-line-height;
Mark Otto's avatar
Mark Otto committed
98
  color: $input-color;
Mark Otto's avatar
Mark Otto committed
99
  text-align: center;
Mark Otto's avatar
Mark Otto committed
100
  background-color: $input-group-addon-bg;
101
  border: $input-btn-border-width solid $input-group-addon-border-color;
102
  @include border-radius($input-border-radius);
Mark Otto's avatar
Mark Otto committed
103
104

  // Sizing
105
  &.form-control-sm {
106
    padding: $input-padding-y-sm $input-padding-x-sm;
Mark Otto's avatar
Mark Otto committed
107
    font-size: $font-size-sm;
108
    @include border-radius($input-border-radius-sm);
Mark Otto's avatar
Mark Otto committed
109
  }
110
  &.form-control-lg {
Mark Otto's avatar
Mark Otto committed
111
    padding: $input-padding-y-lg $input-padding-x-lg;
Mark Otto's avatar
Mark Otto committed
112
    font-size: $font-size-lg;
113
    @include border-radius($input-border-radius-lg);
Mark Otto's avatar
Mark Otto committed
114
115
  }

Mark Otto's avatar
Mark Otto committed
116
  // scss-lint:disable QualifyingElement
Mark Otto's avatar
Mark Otto committed
117
118
119
120
121
  // Nuke default margins from checkboxes and radios to vertically center within.
  input[type="radio"],
  input[type="checkbox"] {
    margin-top: 0;
  }
Mark Otto's avatar
Mark Otto committed
122
  // scss-lint:enable QualifyingElement
Mark Otto's avatar
Mark Otto committed
123
124
}

125
126

//
Mark Otto's avatar
Mark Otto committed
127
// Reset rounded corners
128
129
//

130
131
132
133
134
135
136
.input-group .form-control:not(:last-child),
.input-group-addon:not(:last-child),
.input-group-btn:not(:last-child) > .btn,
.input-group-btn:not(:last-child) > .btn-group > .btn,
.input-group-btn:not(:last-child) > .dropdown-toggle,
.input-group-btn:not(:first-child) > .btn:not(:last-child):not(.dropdown-toggle),
.input-group-btn:not(:first-child) > .btn-group:not(:last-child) > .btn {
Mark Otto's avatar
Mark Otto committed
137
  @include border-right-radius(0);
Mark Otto's avatar
Mark Otto committed
138
}
139
.input-group-addon:not(:last-child) {
Mark Otto's avatar
Mark Otto committed
140
141
  border-right: 0;
}
142
143
144
145
146
147
148
.input-group .form-control:not(:first-child),
.input-group-addon:not(:first-child),
.input-group-btn:not(:first-child) > .btn,
.input-group-btn:not(:first-child) > .btn-group > .btn,
.input-group-btn:not(:first-child) > .dropdown-toggle,
.input-group-btn:not(:last-child) > .btn:not(:first-child),
.input-group-btn:not(:last-child) > .btn-group:not(:first-child) > .btn {
Mark Otto's avatar
Mark Otto committed
149
  @include border-left-radius(0);
Mark Otto's avatar
Mark Otto committed
150
}
151
.form-control + .input-group-addon:not(:first-child) {
Mark Otto's avatar
Mark Otto committed
152
153
154
  border-left: 0;
}

155
//
Mark Otto's avatar
Mark Otto committed
156
// Button input groups
157
158
//

Mark Otto's avatar
Mark Otto committed
159
160
.input-group-btn {
  position: relative;
161
162
  // Jankily prevent input button groups from wrapping with `white-space` and
  // `font-size` in combination with `inline-block` on buttons.
163
  font-size: 0;
Mark Otto's avatar
Mark Otto committed
164
  white-space: nowrap;
165

166
167
  // Negative margin for spacing, position for bringing hovered/focused/actived
  // element above the siblings.
Zlatan Vasović's avatar
Zlatan Vasović committed
168
169
  > .btn {
    position: relative;
170
171
172
173
174
175

    @if $enable-flex {
      // Vertically stretch the button and center its content
      flex: 1;
    }

Zlatan Vasović's avatar
Zlatan Vasović committed
176
    + .btn {
177
      margin-left: (-$input-btn-border-width);
Zlatan Vasović's avatar
Zlatan Vasović committed
178
    }
179

Zlatan Vasović's avatar
Zlatan Vasović committed
180
    // Bring the "active" button to the front
181
    @include hover-focus-active {
Chris Rebert's avatar
Chris Rebert committed
182
      z-index: 3;
Zlatan Vasović's avatar
Zlatan Vasović committed
183
    }
Mark Otto's avatar
Mark Otto committed
184
  }
185

186
  // Negative margin to only have a single, shared border between the two
187
  &:not(:last-child) {
188
189
    > .btn,
    > .btn-group {
190
      margin-right: (-$input-btn-border-width);
191
    }
192
  }
193
  &:not(:first-child) {
194
195
    > .btn,
    > .btn-group {
196
      z-index: 2;
197
      margin-left: (-$input-btn-border-width);
Chris Rebert's avatar
Chris Rebert committed
198
199
200
201
      // Because specificity
      @include hover-focus-active {
        z-index: 3;
      }
202
    }
203
  }
Mark Otto's avatar
Mark Otto committed
204
}