_input-group.scss 4.25 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
7
8
9
10
11
12
13
14
15
  position: relative;

  @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
16
17

  .form-control {
18
19
20
21
    // 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
22
23
24
25
    // Bring the "active" form control to the front
    @include hover-focus-active {
      z-index: 3;
    }
26
27
28
29
30
31
32
33
34
    @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
35
36
37
38
    margin-bottom: 0;
  }
}

39
40
41
.input-group-addon,
.input-group-btn,
.input-group .form-control {
42
43
44
45
46
  @if $enable-flex {
    // do nothing
  } @else {
    display: table-cell;
  }
47
48
49
50
51
52
53
54

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

.input-group-addon,
.input-group-btn {
55
56
57
58
59
  @if $enable-flex {
    // do nothing
  } @else {
    width: 1%;
  }
60
61
62
63
64
  white-space: nowrap;
  vertical-align: middle; // Match the inputs
}


65
66
67
68
69
70
// Sizing options
//
// Remix the default form control sizing classes into new ones for easier
// manipulation.

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


82
//
Mark Otto's avatar
Mark Otto committed
83
// Text input groups
84
85
//

Mark Otto's avatar
Mark Otto committed
86
.input-group-addon {
87
  padding: $input-padding-y $input-padding-x;
Mark Otto's avatar
Mark Otto committed
88
  font-size: $font-size-base;
Mark Otto's avatar
Mark Otto committed
89
  font-weight: normal;
geedmo's avatar
geedmo committed
90
  line-height: 1;
Mark Otto's avatar
Mark Otto committed
91
  color: $input-color;
Mark Otto's avatar
Mark Otto committed
92
  text-align: center;
Mark Otto's avatar
Mark Otto committed
93
94
  background-color: $input-group-addon-bg;
  border: 1px solid $input-group-addon-border-color;
95
  @include border-radius($border-radius);
Mark Otto's avatar
Mark Otto committed
96
97

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

  // Nuke default margins from checkboxes and radios to vertically center within.
  input[type="radio"],
  input[type="checkbox"] {
    margin-top: 0;
  }
}

116
117

//
Mark Otto's avatar
Mark Otto committed
118
// Reset rounded corners
119
120
//

Mark Otto's avatar
Mark Otto committed
121
122
123
.input-group .form-control:first-child,
.input-group-addon:first-child,
.input-group-btn:first-child > .btn,
124
.input-group-btn:first-child > .btn-group > .btn,
Mark Otto's avatar
Mark Otto committed
125
.input-group-btn:first-child > .dropdown-toggle,
126
127
.input-group-btn:last-child > .btn:not(:last-child):not(.dropdown-toggle),
.input-group-btn:last-child > .btn-group:not(:last-child) > .btn {
Mark Otto's avatar
Mark Otto committed
128
  @include border-right-radius(0);
Mark Otto's avatar
Mark Otto committed
129
130
131
132
133
134
135
}
.input-group-addon:first-child {
  border-right: 0;
}
.input-group .form-control:last-child,
.input-group-addon:last-child,
.input-group-btn:last-child > .btn,
136
.input-group-btn:last-child > .btn-group > .btn,
Mark Otto's avatar
Mark Otto committed
137
.input-group-btn:last-child > .dropdown-toggle,
138
139
.input-group-btn:first-child > .btn:not(:first-child),
.input-group-btn:first-child > .btn-group:not(:first-child) > .btn {
Mark Otto's avatar
Mark Otto committed
140
  @include border-left-radius(0);
Mark Otto's avatar
Mark Otto committed
141
142
143
144
145
}
.input-group-addon:last-child {
  border-left: 0;
}

146
147

//
Mark Otto's avatar
Mark Otto committed
148
// Button input groups
149
150
//

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

158
159
  // Negative margin for spacing, position for bringing hovered/focused/actived
  // element above the siblings.
Zlatan Vasović's avatar
Zlatan Vasović committed
160
161
162
  > .btn {
    position: relative;
    + .btn {
163
      margin-left: -1px;
Zlatan Vasović's avatar
Zlatan Vasović committed
164
165
    }
    // Bring the "active" button to the front
166
    @include hover-focus-active {
Chris Rebert's avatar
Chris Rebert committed
167
      z-index: 3;
Zlatan Vasović's avatar
Zlatan Vasović committed
168
    }
Mark Otto's avatar
Mark Otto committed
169
  }
170
171

  // Negative margin to only have a 1px border between the two
172
173
174
175
176
  &:first-child {
    > .btn,
    > .btn-group {
      margin-right: -1px;
    }
177
  }
178
179
180
  &:last-child {
    > .btn,
    > .btn-group {
181
      z-index: 2;
182
      margin-left: -1px;
Chris Rebert's avatar
Chris Rebert committed
183
184
185
186
      // Because specificity
      @include hover-focus-active {
        z-index: 3;
      }
187
    }
188
  }
Mark Otto's avatar
Mark Otto committed
189
}