dropdowns.less 4.7 KB

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