_button-group.scss 2.96 KB
Newer Older
XhmikosR's avatar
XhmikosR committed
1
// stylelint-disable selector-no-qualifying-type
Mark Otto's avatar
Mark Otto committed
2

3
// Make the div behave like a button
4
5
.btn-group,
.btn-group-vertical {
6
  position: relative;
7
  display: inline-flex;
8
  vertical-align: middle; // match .btn alignment given font-size hack above
Mark Otto's avatar
Mark Otto committed
9

Mark Otto's avatar
Mark Otto committed
10
  > .btn {
11
    position: relative;
12
    flex: 1 1 auto;
13
  }
Mark Otto's avatar
Mark Otto committed
14

15
16
  // Bring the hover, focused, and "active" buttons to the front to overlay
  // the borders properly
Martijn Cuppens's avatar
Martijn Cuppens committed
17
18
  > .btn-check:checked + .btn,
  > .btn-check:focus + .btn,
19
20
21
22
23
  > .btn:hover,
  > .btn:focus,
  > .btn:active,
  > .btn.active {
    z-index: 1;
Mark Otto's avatar
Mark Otto committed
24
  }
25
26
}

27
// Optional: Group multiple button groups together for a toolbar
28
.btn-toolbar {
Mark Otto's avatar
Mark Otto committed
29
  display: flex;
30
  flex-wrap: wrap;
Mark Otto's avatar
Mark Otto committed
31
  justify-content: flex-start;
32
33
34
35

  .input-group {
    width: auto;
  }
36
37
}

38
.btn-group {
39
40
41
42
  // Prevent double borders when buttons are next to each other
  > .btn:not(:first-child),
  > .btn-group:not(:first-child) {
    margin-left: -$btn-border-width;
43
44
  }

ysds's avatar
ysds committed
45
46
47
48
  // Reset rounded corners
  > .btn:not(:last-child):not(.dropdown-toggle),
  > .btn-group:not(:last-child) > .btn {
    @include border-right-radius(0);
49
  }
50

51
52
53
54
  // The left radius should be 0 if the button is:
  // - the "third or more" child
  // - the second child and the previous element isn't `.btn-check` (making it the first child visually)
  // - part of a btn-group which isn't the first child
55
  > .btn:nth-child(n + 3),
56
  > :not(.btn-check) + .btn,
ysds's avatar
ysds committed
57
  > .btn-group:not(:first-child) > .btn {
58
59
60
    @include border-left-radius(0);
  }
}
61

62
63
64
65
// Sizing
//
// Remix the default button sizing classes into new ones for easier manipulation.

Mark Otto's avatar
Mark Otto committed
66
67
.btn-group-sm > .btn { @extend .btn-sm; }
.btn-group-lg > .btn { @extend .btn-lg; }
68

69

Mark Otto's avatar
Mark Otto committed
70
//
71
// Split button dropdowns
Mark Otto's avatar
Mark Otto committed
72
//
73

Mark Otto's avatar
Mark Otto committed
74
.dropdown-toggle-split {
75
76
  padding-right: $btn-padding-x * .75;
  padding-left: $btn-padding-x * .75;
77

ysds's avatar
ysds committed
78
79
80
  &::after,
  .dropup &::after,
  .dropright &::after {
81
    margin-left: 0;
82
  }
ysds's avatar
ysds committed
83
84
85
86

  .dropleft &::before {
    margin-right: 0;
  }
87
}
88

89
.btn-sm + .dropdown-toggle-split {
90
91
  padding-right: $btn-padding-x-sm * .75;
  padding-left: $btn-padding-x-sm * .75;
92
93
94
}

.btn-lg + .dropdown-toggle-split {
95
96
  padding-right: $btn-padding-x-lg * .75;
  padding-left: $btn-padding-x-lg * .75;
97
98
99
}


100
// The clickable button for toggling the menu
101
102
// Set the same inset shadow as the :active state
.btn-group.show .dropdown-toggle {
103
  @include box-shadow($btn-active-box-shadow);
104
105
106

  // Show no shadow for `.btn-link` since it has no other button styles.
  &.btn-link {
Mark Otto's avatar
Mark Otto committed
107
    @include box-shadow(none);
108
  }
109
}
110

Mark Otto's avatar
Mark Otto committed
111

Mark Otto's avatar
Mark Otto committed
112
//
113
// Vertical button groups
Mark Otto's avatar
Mark Otto committed
114
//
115

Mark Otto's avatar
derp    
Mark Otto committed
116
.btn-group-vertical {
Mark Otto's avatar
Mark Otto committed
117
118
  flex-direction: column;
  align-items: flex-start;
Mark Otto's avatar
linting    
Mark Otto committed
119
  justify-content: center;
Mark Otto's avatar
Mark Otto committed
120

121
122
  > .btn,
  > .btn-group {
123
    width: 100%;
124
125
  }

126
127
  > .btn:not(:first-child),
  > .btn-group:not(:first-child) {
128
    margin-top: -$btn-border-width;
129
  }
Mark Otto's avatar
derp    
Mark Otto committed
130

ysds's avatar
ysds committed
131
132
133
134
  // Reset rounded corners
  > .btn:not(:last-child):not(.dropdown-toggle),
  > .btn-group:not(:last-child) > .btn {
    @include border-bottom-radius(0);
Mark Otto's avatar
Mark Otto committed
135
136
  }

ysds's avatar
ysds committed
137
138
  > .btn:not(:first-child),
  > .btn-group:not(:first-child) > .btn {
Mark Otto's avatar
Mark Otto committed
139
    @include border-top-radius(0);
Mark Otto's avatar
derp    
Mark Otto committed
140
141
  }
}