_dropdown.scss 4.09 KB
Newer Older
1
2
3
4
//
// Dropdown menus
// --------------------------------------------------

5

Guillermo González de Agüero's avatar
Guillermo González de Agüero committed
6
// The dropdown wrapper (div)
7
.dropup,
Guillermo González de Agüero's avatar
Guillermo González de Agüero committed
8
9
10
11
.dropdown {
  position: relative;
}

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

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

32
33
34
// The dropdown menu (ul)
.dropdown-menu {
  position: absolute;
35
  top: 100%;
36
  left: 0;
Mark Otto's avatar
Mark Otto committed
37
  z-index: $zindex-dropdown;
38
  display: none; // none by default, but block on "open" of the menu
Jacob Thornton's avatar
Jacob Thornton committed
39
  float: left;
40
  min-width: 160px;
Mark Otto's avatar
Mark Otto committed
41
  padding: 5px 0;
Mark Otto's avatar
Mark Otto committed
42
  margin: 2px 0 0; // override default ul
Mark Otto's avatar
Mark Otto committed
43
  font-size: $font-size-base;
44
  text-align: left; // Ensures proper alignment if parent has it changed (e.g., modal footer)
45
  list-style: none;
Mark Otto's avatar
Mark Otto committed
46
  background-color: $dropdown-bg;
47
  background-clip: padding-box;
Mark Otto's avatar
Mark Otto committed
48
  border: 1px solid $dropdown-border;
49
  @include border-radius($border-radius);
Mark Otto's avatar
Mark Otto committed
50
  @include box-shadow(0 6px 12px rgba(0,0,0,.175));
51
52

  // Dividers (basically an hr) within the dropdown
53
  .dropdown-divider {
Mark Otto's avatar
Mark Otto committed
54
    @include nav-divider($dropdown-divider-bg);
55
  }
56
}
57

Mark Otto's avatar
Mark Otto committed
58
59
60
61
62
63
64
65
66
67
// Links, buttons, and more within the dropdown menu
.dropdown-item {
  display: block;
  padding: 3px 20px;
  clear: both;
  font-weight: normal;
  line-height: $line-height;
  color: $dropdown-link-color;
  white-space: nowrap; // prevent links from randomly breaking onto new lines

68
  @include hover-focus {
Mark Otto's avatar
Mark Otto committed
69
    color: $dropdown-link-hover-color;
70
    text-decoration: none;
Mark Otto's avatar
Mark Otto committed
71
    background-color: $dropdown-link-hover-bg;
72
  }
73

Mark Otto's avatar
Mark Otto committed
74
75
76
77
78
79
80
81
  // Active state
  &.active {
    @include plain-hover-focus {
      color: $dropdown-link-active-color;
      text-decoration: none;
      background-color: $dropdown-link-active-bg;
      outline: 0;
    }
82
  }
83

Mark Otto's avatar
Mark Otto committed
84
85
86
87
88
89
90
  // Disabled state
  //
  // Gray out text and ensure the hover/focus state remains gray
  &.disabled {
    @include plain-hover-focus {
      color: $dropdown-link-disabled-color;
    }
vsn4ik's avatar
vsn4ik committed
91

Mark Otto's avatar
Mark Otto committed
92
93
94
95
96
97
98
99
    // Nuke hover/focus effects
    @include hover-focus {
      text-decoration: none;
      cursor: $cursor-disabled;
      background-color: transparent;
      background-image: none; // Remove CSS gradient
      @include reset-filter();
    }
100
  }
101
102
}

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

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

116
117
118
119
120
121
// Menu positioning
//
// Add extra class to `.dropdown-menu` to flip the alignment of the dropdown
// menu with the parent.
.dropdown-menu-right {
  right: 0;
122
  left: auto; // Reset the default from `.dropdown-menu`
123
124
125
126
127
128
129
130
131
}
// With v3, we enabled auto-flipping if you have a dropdown within a right
// aligned nav component. To enable the undoing of that, we provide an override
// to restore the default dropdown menu alignment.
//
// This is only for left-aligning a dropdown menu within a `.navbar-right` or
// `.pull-right` nav component.
.dropdown-menu-left {
  right: auto;
132
  left: 0;
133
134
}

135
136
137
138
// Dropdown section headers
.dropdown-header {
  display: block;
  padding: 3px 20px;
Mark Otto's avatar
Mark Otto committed
139
  font-size: $font-size-sm;
140
  line-height: $line-height;
Mark Otto's avatar
Mark Otto committed
141
  color: $dropdown-header-color;
142
  white-space: nowrap; // as with > li > a
143
144
}

145
146
147
// Backdrop to catch body clicks on mobile, etc.
.dropdown-backdrop {
  position: fixed;
148
  top: 0;
149
150
  right: 0;
  bottom: 0;
151
  left: 0;
Mark Otto's avatar
Mark Otto committed
152
  z-index: ($zindex-dropdown - 10);
153
154
}

Mark Otto's avatar
Mark Otto committed
155
// Right aligned dropdowns
156
.pull-right > .dropdown-menu {
Mark Otto's avatar
Mark Otto committed
157
  right: 0;
Jacob Thornton's avatar
Jacob Thornton committed
158
  left: auto;
Mark Otto's avatar
Mark Otto committed
159
160
}

161
// Allow for dropdowns to go bottom up (aka, dropup-menu)
162
//
163
// Just add .dropup after the standard .dropdown class and you're set, bro.
164
// TODO: abstract this so that the navbar fixed styles are not placed here?
165

166
167
.dropup,
.navbar-fixed-bottom .dropdown {
168
169
  // Reverse the caret
  .caret {
170
    content: "";
171
    border-top: 0;
172
    border-bottom: $caret-width solid;
173
  }
Chris Rebert's avatar
Chris Rebert committed
174

175
176
177
178
  // Different positioning for bottom up menu
  .dropdown-menu {
    top: auto;
    bottom: 100%;
179
    margin-bottom: 2px;
180
181
  }
}