_dropdown.scss 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // The dropdown wrapper (`<div>`)
  2. .dropup,
  3. .dropdown {
  4. position: relative;
  5. }
  6. .dropdown-toggle {
  7. // Generate the caret automatically
  8. &::after {
  9. display: inline-block;
  10. width: 0;
  11. height: 0;
  12. margin-left: $caret-width;
  13. vertical-align: middle;
  14. content: "";
  15. border-top: $caret-width solid;
  16. border-right: $caret-width solid transparent;
  17. border-left: $caret-width solid transparent;
  18. }
  19. // Prevent the focus on the dropdown toggle when closing dropdowns
  20. &:focus {
  21. outline: 0;
  22. }
  23. }
  24. .dropup {
  25. .dropdown-toggle {
  26. &::after {
  27. border-top: 0;
  28. border-bottom: $caret-width solid;
  29. }
  30. }
  31. }
  32. // The dropdown menu
  33. .dropdown-menu {
  34. position: absolute;
  35. top: 100%;
  36. left: 0;
  37. z-index: $zindex-dropdown;
  38. display: none; // none by default, but block on "open" of the menu
  39. float: left;
  40. min-width: $dropdown-min-width;
  41. padding: $dropdown-padding-y 0;
  42. margin: $dropdown-margin-top 0 0; // override default ul
  43. font-size: $font-size-base;
  44. color: $body-color;
  45. text-align: left; // Ensures proper alignment if parent has it changed (e.g., modal footer)
  46. list-style: none;
  47. background-color: $dropdown-bg;
  48. background-clip: padding-box;
  49. border: $dropdown-border-width solid $dropdown-border-color;
  50. @include border-radius($border-radius);
  51. @include box-shadow($dropdown-box-shadow);
  52. }
  53. // Dividers (basically an `<hr>`) within the dropdown
  54. .dropdown-divider {
  55. @include nav-divider($dropdown-divider-bg);
  56. }
  57. // Links, buttons, and more within the dropdown menu
  58. //
  59. // `<button>`-specific styles are denoted with `// For <button>s`
  60. .dropdown-item {
  61. display: block;
  62. width: 100%; // For `<button>`s
  63. padding: 3px $dropdown-item-padding-x;
  64. clear: both;
  65. font-weight: normal;
  66. color: $dropdown-link-color;
  67. text-align: inherit; // For `<button>`s
  68. white-space: nowrap; // prevent links from randomly breaking onto new lines
  69. background: none; // For `<button>`s
  70. border: 0; // For `<button>`s
  71. @include hover-focus {
  72. color: $dropdown-link-hover-color;
  73. text-decoration: none;
  74. background-color: $dropdown-link-hover-bg;
  75. }
  76. // Active state
  77. &.active {
  78. @include plain-hover-focus {
  79. color: $dropdown-link-active-color;
  80. text-decoration: none;
  81. background-color: $dropdown-link-active-bg;
  82. outline: 0;
  83. }
  84. }
  85. // Disabled state
  86. //
  87. // Gray out text and ensure the hover/focus state remains gray
  88. &.disabled {
  89. @include plain-hover-focus {
  90. color: $dropdown-link-disabled-color;
  91. }
  92. // Nuke hover/focus effects
  93. @include hover-focus {
  94. text-decoration: none;
  95. cursor: $cursor-disabled;
  96. background-color: transparent;
  97. background-image: none; // Remove CSS gradient
  98. @include reset-filter();
  99. }
  100. }
  101. }
  102. // Open state for the dropdown
  103. .open {
  104. // Show the menu
  105. > .dropdown-menu {
  106. display: block;
  107. }
  108. // Remove the outline when :focus is triggered
  109. > a {
  110. outline: 0;
  111. }
  112. }
  113. // Menu positioning
  114. //
  115. // Add extra class to `.dropdown-menu` to flip the alignment of the dropdown
  116. // menu with the parent.
  117. .dropdown-menu-right {
  118. right: 0;
  119. left: auto; // Reset the default from `.dropdown-menu`
  120. }
  121. .dropdown-menu-left {
  122. right: auto;
  123. left: 0;
  124. }
  125. // Dropdown section headers
  126. .dropdown-header {
  127. display: block;
  128. padding: $dropdown-padding-y $dropdown-item-padding-x;
  129. margin-bottom: 0; // for use with heading elements
  130. font-size: $font-size-sm;
  131. color: $dropdown-header-color;
  132. white-space: nowrap; // as with > li > a
  133. }
  134. // Backdrop to catch body clicks on mobile, etc.
  135. .dropdown-backdrop {
  136. position: fixed;
  137. top: 0;
  138. right: 0;
  139. bottom: 0;
  140. left: 0;
  141. z-index: $zindex-dropdown-backdrop;
  142. }
  143. // Allow for dropdowns to go bottom up (aka, dropup-menu)
  144. //
  145. // Just add .dropup after the standard .dropdown class and you're set.
  146. // TODO: abstract this so that the navbar fixed styles are not placed here?
  147. .dropup,
  148. .navbar-fixed-bottom .dropdown {
  149. // Reverse the caret
  150. .caret {
  151. content: "";
  152. border-top: 0;
  153. border-bottom: $caret-width solid;
  154. }
  155. // Different positioning for bottom up menu
  156. .dropdown-menu {
  157. top: auto;
  158. bottom: 100%;
  159. margin-bottom: $dropdown-margin-top;
  160. }
  161. }