dropdowns.mdx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. ---
  2. title: Dropdowns
  3. summary: Use dropdowns to display lists of options or include more items in a menu without overwhelming users with too many buttons and long lists. Dropdowns facilitate users' interaction with your website or software and make your design look clear.
  4. bootstrapLink: components/dropdowns
  5. description: Organize options with dropdown menus.
  6. ---
  7. ## Default dropdown
  8. With small markup changes, you can turn any `.btn` into a dropdown toggle and use it to display more options for users to choose from. Start with the default dropdown and then use additional classes to make your dropdown more user-friendly.
  9. ```html example height="16rem"
  10. <div class="dropdown">
  11. <a href="#" class="btn dropdown-toggle" data-bs-toggle="dropdown">Open dropdown</a>
  12. <div class="dropdown-menu">
  13. <a class="dropdown-item" href="#">Action</a>
  14. <a class="dropdown-item" href="#">Another action</a>
  15. <a class="dropdown-item" href="#">Third action</a>
  16. </div>
  17. </div>
  18. ```
  19. ## Dropdown divider
  20. Use dropdown dividers to separate groups of dropdown items for greater clarity.
  21. ```html example height="16rem"
  22. <div class="dropdown">
  23. <a href="#" class="btn dropdown-toggle" data-bs-toggle="dropdown">Open dropdown</a>
  24. <div class="dropdown-menu">
  25. <a class="dropdown-item" href="#"> Action </a>
  26. <a class="dropdown-item" href="#"> Another action </a>
  27. <div class="dropdown-divider"></div>
  28. <a class="dropdown-item" href="#">Separated link</a>
  29. </div>
  30. </div>
  31. ```
  32. ## Active state
  33. Make a dropdown item look active, so that it highlights when a user hovers over a given option.
  34. ```html example height="16rem"
  35. <div class="dropdown">
  36. <a href="#" class="btn dropdown-toggle" data-bs-toggle="dropdown">Open dropdown</a>
  37. <div class="dropdown-menu">
  38. <a class="dropdown-item" href="#"> Action </a>
  39. <a class="dropdown-item" href="#"> Another action </a>
  40. <a class="dropdown-item active" href="#">Active action</a>
  41. </div>
  42. </div>
  43. ```
  44. ## Disabled state
  45. Make a dropdown item look disabled to display options which are currently not available but can activate once certain conditions are met.
  46. ```html example height="16rem"
  47. <div class="dropdown">
  48. <a href="#" class="btn dropdown-toggle" data-bs-toggle="dropdown">Open dropdown</a>
  49. <div class="dropdown-menu">
  50. <a class="dropdown-item" href="#"> Action </a>
  51. <a class="dropdown-item" href="#"> Another action </a>
  52. <a class="dropdown-item disabled" href="#">Disabled action</a>
  53. </div>
  54. </div>
  55. ```
  56. ## Dropdown header
  57. Add a dropdown header to group dropdown items into sections and name them accordingly.
  58. ```html example height="16rem"
  59. <div class="dropdown">
  60. <a href="#" class="btn dropdown-toggle" data-bs-toggle="dropdown">Open dropdown</a>
  61. <div class="dropdown-menu">
  62. <span class="dropdown-header">Dropdown header</span>
  63. <a class="dropdown-item" href="#"> Action </a>
  64. <a class="dropdown-item" href="#"> Another action </a>
  65. </div>
  66. </div>
  67. ```
  68. ## Dropdown with icons
  69. Use icons in your dropdowns to add more visual content and make the options easy to identify for users.
  70. ```html example height="16rem"
  71. <div class="dropdown">
  72. <a href="#" class="btn dropdown-toggle" data-bs-toggle="dropdown">Open dropdown</a>
  73. <div class="dropdown-menu">
  74. <span class="dropdown-header">Dropdown header</span>
  75. <a class="dropdown-item" href="#">
  76. <svg
  77. xmlns="http://www.w3.org/2000/svg"
  78. class="icon dropdown-item-icon icon-tabler icon-tabler-settings"
  79. width="24"
  80. height="24"
  81. viewBox="0 0 24 24"
  82. stroke-width="2"
  83. stroke="currentColor"
  84. fill="none"
  85. stroke-linecap="round"
  86. stroke-linejoin="round"
  87. >
  88. <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
  89. <path
  90. d="M10.325 4.317c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756 .426 1.756 2.924 0 3.35a1.724 1.724 0 0 0 -1.066 2.573c.94 1.543 -.826 3.31 -2.37 2.37a1.724 1.724 0 0 0 -2.572 1.065c-.426 1.756 -2.924 1.756 -3.35 0a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065z"
  91. ></path>
  92. <path d="M12 12m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"></path>
  93. </svg>
  94. Action
  95. </a>
  96. <a class="dropdown-item" href="#">
  97. <svg
  98. xmlns="http://www.w3.org/2000/svg"
  99. class="icon dropdown-item-icon icon-tabler icon-tabler-pencil"
  100. width="24"
  101. height="24"
  102. viewBox="0 0 24 24"
  103. stroke-width="2"
  104. stroke="currentColor"
  105. fill="none"
  106. stroke-linecap="round"
  107. stroke-linejoin="round"
  108. >
  109. <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
  110. <path d="M4 20h4l10.5 -10.5a1.5 1.5 0 0 0 -4 -4l-10.5 10.5v4"></path>
  111. <path d="M13.5 6.5l4 4"></path>
  112. </svg>
  113. Another action
  114. </a>
  115. </div>
  116. </div>
  117. ```
  118. ## Dropdown with arrow
  119. Add an arrow that points at the dropdown button.
  120. ```html example height="16rem"
  121. <div class="dropdown">
  122. <a href="#" class="btn dropdown-toggle" data-bs-toggle="dropdown">Open dropdown</a>
  123. <div class="dropdown-menu dropdown-menu-arrow">
  124. <a class="dropdown-item" href="#"> Action </a>
  125. <a class="dropdown-item" href="#"> Another action </a>
  126. </div>
  127. </div>
  128. ```
  129. ## Dropdown with badge
  130. Add a badge to your dropdown items to show additional information related to an item or distinguish it from other elements.
  131. ```html example height="16rem"
  132. <div class="dropdown">
  133. <a href="#" class="btn dropdown-toggle" data-bs-toggle="dropdown">Open dropdown</a>
  134. <div class="dropdown-menu">
  135. <a class="dropdown-item" href="#">
  136. Action
  137. <span class="badge bg-primary ms-auto">12</span>
  138. </a>
  139. <a class="dropdown-item" href="#">
  140. Another action
  141. <span class="badge bg-green ms-auto"></span>
  142. </a>
  143. </div>
  144. </div>
  145. ```
  146. ## Dropdown with checkboxes
  147. Use dropdowns with checkboxes to allow users to select options from a predefined list. Dropdowns with checkboxes are particularly useful for filtering.
  148. ```html example height="16rem"
  149. <div class="dropdown">
  150. <a href="#" class="btn dropdown-toggle" data-bs-toggle="dropdown">Open dropdown</a>
  151. <div class="dropdown-menu">
  152. <label class="dropdown-item">
  153. <input class="form-check-input m-0 me-2" type="radio" /> Option 1
  154. </label>
  155. <label class="dropdown-item">
  156. <input class="form-check-input m-0 me-2" type="radio" /> Option 2
  157. </label>
  158. <label class="dropdown-item">
  159. <input class="form-check-input m-0 me-2" type="radio" /> Option 3
  160. </label>
  161. </div>
  162. </div>
  163. ```
  164. ## Dark dropdown
  165. Make your dropdown suit the dark mode of your website or software.
  166. ```html example height="16rem"
  167. <div class="dropdown">
  168. <a href="#" class="btn dropdown-toggle" data-bs-toggle="dropdown">Open dropdown</a>
  169. <div class="dropdown-menu dropdown-menu-arrow bg-dark text-white">
  170. <span class="dropdown-header">Dropdown header</span>
  171. <a class="dropdown-item" href="#">
  172. <svg
  173. xmlns="http://www.w3.org/2000/svg"
  174. class="icon dropdown-item-icon"
  175. width="24"
  176. height="24"
  177. viewBox="0 0 24 24"
  178. stroke-width="2"
  179. stroke="currentColor"
  180. fill="none"
  181. stroke-linecap="round"
  182. stroke-linejoin="round"
  183. >
  184. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  185. <path
  186. d="M10.325 4.317c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756 .426 1.756 2.924 0 3.35a1.724 1.724 0 0 0 -1.066 2.573c.94 1.543 -.826 3.31 -2.37 2.37a1.724 1.724 0 0 0 -2.572 1.065c-.426 1.756 -2.924 1.756 -3.35 0a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065z"
  187. />
  188. <circle cx="12" cy="12" r="3" />
  189. </svg>
  190. Action
  191. </a>
  192. <a class="dropdown-item" href="#">
  193. <svg
  194. xmlns="http://www.w3.org/2000/svg"
  195. class="icon dropdown-item-icon"
  196. width="24"
  197. height="24"
  198. viewBox="0 0 24 24"
  199. stroke-width="2"
  200. stroke="currentColor"
  201. fill="none"
  202. stroke-linecap="round"
  203. stroke-linejoin="round"
  204. >
  205. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  206. <path d="M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1" />
  207. <path d="M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415z" />
  208. <path d="M16 5l3 3" />
  209. </svg>
  210. Another action
  211. </a>
  212. </div>
  213. </div>
  214. ```
  215. ## Dropdown with card content
  216. Use a dropdown with card content to make it easy for users to get more information on a given subject and avoid ovewhelming them with too much content at once.
  217. ```html example height="35rem"
  218. <div class="dropdown">
  219. <a href="#" class="btn dropdown-toggle" data-bs-toggle="dropdown">Open dropdown</a>
  220. <div class="dropdown-menu dropdown-menu-card" style="max-width: 16rem">
  221. <div class="card d-flex flex-column">
  222. <a href="#">
  223. <img
  224. class="card-img-top"
  225. src="/samples/photos/friends-at-a-restaurant-drinking-wine.jpg"
  226. alt="How do you know she is a witch?"
  227. />
  228. </a>
  229. <div class="card-body d-flex flex-column">
  230. <h3 class="card-title">
  231. <a href="#">How do you know she is a witch?</a>
  232. </h3>
  233. <div class="text-secondary">
  234. Are you suggesting that coconuts migrate? No, no, no! Yes, yes. A bit. But she's got a
  235. wart. You ...
  236. </div>
  237. <div class="d-flex align-items-center pt-4 mt-auto">
  238. <span class="avatar" style="background-image: url(/samples/avatars/013m.jpg)"></span>
  239. <div class="ms-3">
  240. <a href="#" class="text-body">Maryjo Lebarree</a>
  241. <div class="text-secondary">3 days ago</div>
  242. </div>
  243. <div class="ms-auto">
  244. <a href="#" class="icon d-none d-md-inline-block ms-3 text-secondary">
  245. <svg
  246. xmlns="http://www.w3.org/2000/svg"
  247. class="icon"
  248. width="24"
  249. height="24"
  250. viewBox="0 0 24 24"
  251. stroke-width="2"
  252. stroke="currentColor"
  253. fill="none"
  254. stroke-linecap="round"
  255. stroke-linejoin="round"
  256. >
  257. <path stroke="none" d="M0 0h24v24H0z" fill="none" />
  258. <path
  259. d="M19.5 12.572l-7.5 7.428l-7.5 -7.428m0 0a5 5 0 1 1 7.5 -6.566a5 5 0 1 1 7.5 6.572"
  260. />
  261. </svg>
  262. </a>
  263. </div>
  264. </div>
  265. </div>
  266. </div>
  267. </div>
  268. </div>
  269. ```