dropdowns.less 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. //
  2. // Dropdown menus
  3. // --------------------------------------------------
  4. // Dropdown arrow/caret
  5. .caret {
  6. display: inline-block;
  7. width: 0;
  8. height: 0;
  9. margin-left: 2px;
  10. vertical-align: middle;
  11. border-top: @caret-width-base solid;
  12. border-right: @caret-width-base solid transparent;
  13. border-left: @caret-width-base solid transparent;
  14. }
  15. // The dropdown wrapper (div)
  16. .dropdown {
  17. position: relative;
  18. }
  19. // Prevent the focus on the dropdown toggle when closing dropdowns
  20. .dropdown-toggle:focus {
  21. outline: 0;
  22. }
  23. // The dropdown menu (ul)
  24. .dropdown-menu {
  25. position: absolute;
  26. top: 100%;
  27. left: 0;
  28. z-index: @zindex-dropdown;
  29. display: none; // none by default, but block on "open" of the menu
  30. float: left;
  31. min-width: 160px;
  32. padding: 5px 0;
  33. margin: 2px 0 0; // override default ul
  34. list-style: none;
  35. font-size: @font-size-base;
  36. text-align: left; // Ensures proper alignment if parent has it changed (e.g., modal footer)
  37. background-color: @dropdown-bg;
  38. border: 1px solid @dropdown-fallback-border; // IE8 fallback
  39. border: 1px solid @dropdown-border;
  40. border-radius: @border-radius-base;
  41. .box-shadow(0 6px 12px rgba(0,0,0,.175));
  42. background-clip: padding-box;
  43. // Aligns the dropdown menu to right
  44. //
  45. // Deprecated as of 3.1.0 in favor of `.dropdown-menu-[dir]`
  46. &.pull-right {
  47. right: 0;
  48. left: auto;
  49. }
  50. // Dividers (basically an hr) within the dropdown
  51. .divider {
  52. .nav-divider(@dropdown-divider-bg);
  53. }
  54. // Links within the dropdown menu
  55. > li > a {
  56. display: block;
  57. padding: 3px 20px;
  58. clear: both;
  59. font-weight: normal;
  60. line-height: @line-height-base;
  61. color: @dropdown-link-color;
  62. white-space: nowrap; // prevent links from randomly breaking onto new lines
  63. }
  64. }
  65. // Hover/Focus state
  66. .dropdown-menu > li > a {
  67. &:hover,
  68. &:focus {
  69. text-decoration: none;
  70. color: @dropdown-link-hover-color;
  71. background-color: @dropdown-link-hover-bg;
  72. }
  73. }
  74. // Active state
  75. .dropdown-menu > .active > a {
  76. &,
  77. &:hover,
  78. &:focus {
  79. color: @dropdown-link-active-color;
  80. text-decoration: none;
  81. outline: 0;
  82. background-color: @dropdown-link-active-bg;
  83. }
  84. }
  85. // Disabled state
  86. //
  87. // Gray out text and ensure the hover/focus state remains gray
  88. .dropdown-menu > .disabled > a {
  89. &,
  90. &:hover,
  91. &:focus {
  92. color: @dropdown-link-disabled-color;
  93. }
  94. // Nuke hover/focus effects
  95. &:hover,
  96. &:focus {
  97. text-decoration: none;
  98. background-color: transparent;
  99. background-image: none; // Remove CSS gradient
  100. .reset-filter();
  101. cursor: @cursor-disabled;
  102. }
  103. }
  104. // Open state for the dropdown
  105. .open {
  106. // Show the menu
  107. > .dropdown-menu {
  108. display: block;
  109. }
  110. // Remove the outline when :focus is triggered
  111. > a {
  112. outline: 0;
  113. }
  114. }
  115. // Menu positioning
  116. //
  117. // Add extra class to `.dropdown-menu` to flip the alignment of the dropdown
  118. // menu with the parent.
  119. .dropdown-menu-right {
  120. left: auto; // Reset the default from `.dropdown-menu`
  121. right: 0;
  122. }
  123. // With v3, we enabled auto-flipping if you have a dropdown within a right
  124. // aligned nav component. To enable the undoing of that, we provide an override
  125. // to restore the default dropdown menu alignment.
  126. //
  127. // This is only for left-aligning a dropdown menu within a `.navbar-right` or
  128. // `.pull-right` nav component.
  129. .dropdown-menu-left {
  130. left: 0;
  131. right: auto;
  132. }
  133. // Dropdown section headers
  134. .dropdown-header {
  135. display: block;
  136. padding: 3px 20px;
  137. font-size: @font-size-small;
  138. line-height: @line-height-base;
  139. color: @dropdown-header-color;
  140. white-space: nowrap; // as with > li > a
  141. }
  142. // Backdrop to catch body clicks on mobile, etc.
  143. .dropdown-backdrop {
  144. position: fixed;
  145. left: 0;
  146. right: 0;
  147. bottom: 0;
  148. top: 0;
  149. z-index: (@zindex-dropdown - 10);
  150. }
  151. // Right aligned dropdowns
  152. .pull-right > .dropdown-menu {
  153. right: 0;
  154. left: auto;
  155. }
  156. // Allow for dropdowns to go bottom up (aka, dropup-menu)
  157. //
  158. // Just add .dropup after the standard .dropdown class and you're set, bro.
  159. // TODO: abstract this so that the navbar fixed styles are not placed here?
  160. .dropup,
  161. .navbar-fixed-bottom .dropdown {
  162. // Reverse the caret
  163. .caret {
  164. border-top: 0;
  165. border-bottom: @caret-width-base solid;
  166. content: "";
  167. }
  168. // Different positioning for bottom up menu
  169. .dropdown-menu {
  170. top: auto;
  171. bottom: 100%;
  172. margin-bottom: 1px;
  173. }
  174. }
  175. // Component alignment
  176. //
  177. // Reiterate per navbar.less and the modified component alignment there.
  178. @media (min-width: @grid-float-breakpoint) {
  179. .navbar-right {
  180. .dropdown-menu {
  181. .dropdown-menu-right();
  182. }
  183. // Necessary for overrides of the default right aligned menu.
  184. // Will remove come v4 in all likelihood.
  185. .dropdown-menu-left {
  186. .dropdown-menu-left();
  187. }
  188. }
  189. }