dropdowns.less 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. }
  95. // Nuke hover/focus effects
  96. .dropdown-menu > .disabled > a {
  97. &:hover,
  98. &:focus {
  99. text-decoration: none;
  100. background-color: transparent;
  101. background-image: none; // Remove CSS gradient
  102. .reset-filter();
  103. cursor: not-allowed;
  104. }
  105. }
  106. // Open state for the dropdown
  107. .open {
  108. // Show the menu
  109. > .dropdown-menu {
  110. display: block;
  111. }
  112. // Remove the outline when :focus is triggered
  113. > a {
  114. outline: 0;
  115. }
  116. }
  117. // Menu positioning
  118. //
  119. // Add extra class to `.dropdown-menu` to flip the alignment of the dropdown
  120. // menu with the parent.
  121. .dropdown-menu-right {
  122. left: auto; // Reset the default from `.dropdown-menu`
  123. right: 0;
  124. }
  125. // With v3, we enabled auto-flipping if you have a dropdown within a right
  126. // aligned nav component. To enable the undoing of that, we provide an override
  127. // to restore the default dropdown menu alignment.
  128. //
  129. // This is only for left-aligning a dropdown menu within a `.navbar-right` or
  130. // `.pull-right` nav component.
  131. .dropdown-menu-left {
  132. left: 0;
  133. right: auto;
  134. }
  135. // Dropdown section headers
  136. .dropdown-header {
  137. display: block;
  138. padding: 3px 20px;
  139. font-size: @font-size-small;
  140. line-height: @line-height-base;
  141. color: @dropdown-header-color;
  142. white-space: nowrap; // as with > li > a
  143. }
  144. // Backdrop to catch body clicks on mobile, etc.
  145. .dropdown-backdrop {
  146. position: fixed;
  147. left: 0;
  148. right: 0;
  149. bottom: 0;
  150. top: 0;
  151. z-index: (@zindex-dropdown - 10);
  152. }
  153. // Right aligned dropdowns
  154. .pull-right > .dropdown-menu {
  155. right: 0;
  156. left: auto;
  157. }
  158. // Allow for dropdowns to go bottom up (aka, dropup-menu)
  159. //
  160. // Just add .dropup after the standard .dropdown class and you're set, bro.
  161. // TODO: abstract this so that the navbar fixed styles are not placed here?
  162. .dropup,
  163. .navbar-fixed-bottom .dropdown {
  164. // Reverse the caret
  165. .caret {
  166. border-top: 0;
  167. border-bottom: @caret-width-base solid;
  168. content: "";
  169. }
  170. // Different positioning for bottom up menu
  171. .dropdown-menu {
  172. top: auto;
  173. bottom: 100%;
  174. margin-bottom: 1px;
  175. }
  176. }
  177. // Component alignment
  178. //
  179. // Reiterate per navbar.less and the modified component alignment there.
  180. @media (min-width: @grid-float-breakpoint) {
  181. .navbar-right {
  182. .dropdown-menu {
  183. .dropdown-menu-right();
  184. }
  185. // Necessary for overrides of the default right aligned menu.
  186. // Will remove come v4 in all likelihood.
  187. .dropdown-menu-left {
  188. .dropdown-menu-left();
  189. }
  190. }
  191. }