_input-group.scss 4.91 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
29
30
31
32
33
34
35
36
    @if $enable-flex {
      flex: 1;
    } @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
37
38
39
40
    margin-bottom: 0;
  }
}

41
42
43
.input-group-addon,
.input-group-btn,
.input-group .form-control {
44
45
46
47
  @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
48
    justify-content: center;
49
  } @else {
50
51
    display: table-cell;
  }
52
53
54
55
56
57
58
59

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

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


68
69
70
71
72
73
// Sizing options
//
// Remix the default form control sizing classes into new ones for easier
// manipulation.

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


85
//
Mark Otto's avatar
Mark Otto committed
86
// Text input groups
87
88
//

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

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

Mark Otto's avatar
Mark Otto committed
113
  // scss-lint:disable QualifyingElement
Mark Otto's avatar
Mark Otto committed
114
115
116
117
118
  // 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
119
  // scss-lint:enable QualifyingElement
Mark Otto's avatar
Mark Otto committed
120
121
}

122
123

//
Mark Otto's avatar
Mark Otto committed
124
// Reset rounded corners
125
126
//

127
128
129
130
131
132
133
.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
134
  @include border-right-radius(0);
Mark Otto's avatar
Mark Otto committed
135
}
136
.input-group-addon:not(:last-child) {
Mark Otto's avatar
Mark Otto committed
137
138
  border-right: 0;
}
139
140
141
142
143
144
145
.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
146
  @include border-left-radius(0);
Mark Otto's avatar
Mark Otto committed
147
}
148
.form-control + .input-group-addon:not(:first-child) {
Mark Otto's avatar
Mark Otto committed
149
150
151
  border-left: 0;
}

152
//
Mark Otto's avatar
Mark Otto committed
153
// Button input groups
154
155
//

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

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

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

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

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

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