_dropdown.scss 3.72 KB
Newer Older
1
// The dropdown wrapper (`<div>`)
2
.dropup,
Guillermo González de Agüero's avatar
Guillermo González de Agüero committed
3
4
5
6
.dropdown {
  position: relative;
}

7
8
.dropdown-toggle {
  // Generate the caret automatically
9
  &::after {
10
11
12
    display: inline-block;
    width: 0;
    height: 0;
13
    margin-left: $caret-width;
14
    vertical-align: middle;
15
    content: "";
16
17
18
    border-top: $caret-width solid;
    border-right: $caret-width solid transparent;
    border-left: $caret-width solid transparent;
19
20
21
22
23
24
  }

  // Prevent the focus on the dropdown toggle when closing dropdowns
  &:focus {
    outline: 0;
  }
Mark Otto's avatar
Mark Otto committed
25
26
}

27
28
.dropup {
  .dropdown-toggle {
29
    &::after {
Mark Otto's avatar
shorter    
Mark Otto committed
30
      border-top: 0;
Felipe's avatar
Felipe committed
31
      border-bottom: $caret-width solid;
32
33
34
35
    }
  }
}

36
// The dropdown menu
37
38
.dropdown-menu {
  position: absolute;
39
  top: 100%;
40
  left: 0;
Mark Otto's avatar
Mark Otto committed
41
  z-index: $zindex-dropdown;
42
  display: none; // none by default, but block on "open" of the menu
Jacob Thornton's avatar
Jacob Thornton committed
43
  float: left;
44
  min-width: $dropdown-min-width;
45
  padding: $dropdown-padding-y 0;
46
  margin: $dropdown-margin-top 0 0; // override default ul
47
  font-size: $font-size-base; // Redeclare because nesting can cause inheritance issues
48
  color: $body-color;
49
  text-align: left; // Ensures proper alignment if parent has it changed (e.g., modal footer)
50
  list-style: none;
Mark Otto's avatar
Mark Otto committed
51
  background-color: $dropdown-bg;
52
  background-clip: padding-box;
53
  border: $dropdown-border-width solid $dropdown-border-color;
54
  @include border-radius($border-radius);
55
  @include box-shadow($dropdown-box-shadow);
Mark Otto's avatar
Mark Otto committed
56
}
57

58
// Dividers (basically an `<hr>`) within the dropdown
Mark Otto's avatar
Mark Otto committed
59
60
.dropdown-divider {
  @include nav-divider($dropdown-divider-bg);
61
}
62

Mark Otto's avatar
Mark Otto committed
63
// Links, buttons, and more within the dropdown menu
Mark Otto's avatar
Mark Otto committed
64
//
65
// `<button>`-specific styles are denoted with `// For <button>s`
Mark Otto's avatar
Mark Otto committed
66
67
.dropdown-item {
  display: block;
Mark Otto's avatar
Mark Otto committed
68
  width: 100%; // For `<button>`s
69
  padding: 3px $dropdown-item-padding-x;
Mark Otto's avatar
Mark Otto committed
70
  clear: both;
71
  font-weight: $font-weight-normal;
Mark Otto's avatar
Mark Otto committed
72
  color: $dropdown-link-color;
Mark Otto's avatar
Mark Otto committed
73
  text-align: inherit; // For `<button>`s
Mark Otto's avatar
Mark Otto committed
74
  white-space: nowrap; // prevent links from randomly breaking onto new lines
Mark Otto's avatar
Mark Otto committed
75
76
  background: none; // For `<button>`s
  border: 0; // For `<button>`s
77

78
  @include hover-focus {
Mark Otto's avatar
Mark Otto committed
79
    color: $dropdown-link-hover-color;
80
    text-decoration: none;
Mark Otto's avatar
Mark Otto committed
81
    background-color: $dropdown-link-hover-bg;
82
  }
83

Mark Otto's avatar
Mark Otto committed
84
85
86
87
88
  &.active,
  &:active {
    color: $dropdown-link-active-color;
    text-decoration: none;
    background-color: $dropdown-link-active-bg;
89
  }
90

Mark Otto's avatar
Mark Otto committed
91
92
93
94
95
96
97
98
  &.disabled,
  &:disabled {
    color: $dropdown-link-disabled-color;
    cursor: $cursor-disabled;
    background-color: transparent;
    // Remove CSS gradients if they're enabled
    @if $enable-gradients {
      background-image: none;
Mark Otto's avatar
Mark Otto committed
99
    }
100
  }
101
102
}

103
// Open state for the dropdown
Starsam80's avatar
Starsam80 committed
104
.show {
105
106
  // Show the menu
  > .dropdown-menu {
107
    display: block;
108
    overflow: hidden;
109
  }
110
111
112
113
114

  // Remove the outline when :focus is triggered
  > a {
    outline: 0;
  }
115
}
116

117
118
119
120
121
122
// Menu positioning
//
// Add extra class to `.dropdown-menu` to flip the alignment of the dropdown
// menu with the parent.
.dropdown-menu-right {
  right: 0;
123
  left: auto; // Reset the default from `.dropdown-menu`
124
}
Mark Otto's avatar
Mark Otto committed
125

126
127
.dropdown-menu-left {
  right: auto;
128
  left: 0;
129
130
}

131
132
133
// Dropdown section headers
.dropdown-header {
  display: block;
134
  padding: $dropdown-padding-y $dropdown-item-padding-x;
Mark Otto's avatar
Mark Otto committed
135
  margin-bottom: 0; // for use with heading elements
Mark Otto's avatar
Mark Otto committed
136
137
  font-size: $font-size-sm;
  color: $dropdown-header-color;
138
  white-space: nowrap; // as with > li > a
139
140
}

141
142
143
// Backdrop to catch body clicks on mobile, etc.
.dropdown-backdrop {
  position: fixed;
144
  top: 0;
145
146
  right: 0;
  bottom: 0;
147
  left: 0;
148
  z-index: $zindex-dropdown-backdrop;
149
150
}

151
// Allow for dropdowns to go bottom up (aka, dropup-menu)
152
//
Matthew Conlen's avatar
Matthew Conlen committed
153
// Just add .dropup after the standard .dropdown class and you're set.
154

155
.dropup {
156
157
158
159
  // Different positioning for bottom up menu
  .dropdown-menu {
    top: auto;
    bottom: 100%;
160
    margin-bottom: $dropdown-margin-top;
161
162
  }
}