navs-tabls.mdx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. ---
  2. title: Navs and tabs
  3. summary: This guide covered the basics of creating different types of navigation bars and tabs, including horizontal, vertical, pill-shaped, and underline-styled navs.
  4. description: "Essential guide to nav styles: tabs, pills, dropdowns, and more."
  5. ---
  6. Navigation bars are essential components of modern web applications, providing users with intuitive ways to navigate between different sections and content. This guide explores various types of navigation bars and tabs that can be easily implemented using predefined classes in HTML and CSS. Each type serves specific use cases, from horizontal and vertical layouts to tabbed interfaces and dropdown menus. By utilizing these examples, developers can enhance the usability and aesthetics of their web projects.
  7. ## Horizontal nav
  8. If you want to create a horizontal navigation bar, you can use the `.nav` class. The `.nav-item` class is used to style each item within the navigation bar, and `.nav-link` is applied to the links. The `.active` class highlights the current active link, while the `.disabled` class styles non-clickable links.
  9. ```html
  10. <ul class="nav">
  11. <li class="nav-item">
  12. <a class="nav-link active" aria-current="page" href="#">Active</a>
  13. </li>
  14. <li class="nav-item">
  15. <a class="nav-link" href="#">Link</a>
  16. </li>
  17. <li class="nav-item">
  18. <a class="nav-link disabled" aria-disabled="true">Disabled</a>
  19. </li>
  20. </ul>
  21. ```
  22. Look at the example below to see how the horizontal navigation bar is displayed.
  23. ```html example centered
  24. <ul class="nav">
  25. <li class="nav-item">
  26. <a class="nav-link active" aria-current="page" href="#">Active</a>
  27. </li>
  28. <li class="nav-item">
  29. <a class="nav-link" href="#">Link</a>
  30. </li>
  31. <li class="nav-item">
  32. <a class="nav-link" href="#">Link</a>
  33. </li>
  34. <li class="nav-item">
  35. <a class="nav-link disabled" aria-disabled="true">Disabled</a>
  36. </li>
  37. </ul>
  38. ```
  39. ## Vertical nav
  40. To create a vertical navigation bar, add the `.flex-column` class to the `.nav` element. This arranges the navigation items in a column instead of a row, making it suitable for sidebars or vertical menus.
  41. ```html
  42. <ul class="nav flex-column">
  43. ...
  44. </ul>
  45. ```
  46. There is an example below to see how the vertical navigation bar is displayed.
  47. ```html example centered
  48. <ul class="nav flex-column">
  49. <li class="nav-item">
  50. <a class="nav-link active" aria-current="page" href="#">Active</a>
  51. </li>
  52. <li class="nav-item">
  53. <a class="nav-link" href="#">Link</a>
  54. </li>
  55. <li class="nav-item">
  56. <a class="nav-link" href="#">Link</a>
  57. </li>
  58. <li class="nav-item">
  59. <a class="nav-link disabled" aria-disabled="true">Disabled</a>
  60. </li>
  61. </ul>
  62. ```
  63. ## Tabs
  64. To create a tabbed navigation interface, use the `.nav-tabs` class. This is ideal for displaying different content sections within a single interface, where each tab represents a section.
  65. ```html
  66. <ul class="nav nav-tabs">
  67. ...
  68. </ul>
  69. ```
  70. Example below shows how the tabbed navigation interface is displayed.
  71. ```html example centered
  72. <ul class="nav nav-tabs">
  73. <li class="nav-item">
  74. <a class="nav-link active" aria-current="page" href="#">Active</a>
  75. </li>
  76. <li class="nav-item">
  77. <a class="nav-link" href="#">Link</a>
  78. </li>
  79. <li class="nav-item">
  80. <a class="nav-link" href="#">Link</a>
  81. </li>
  82. <li class="nav-item">
  83. <a class="nav-link disabled" aria-disabled="true">Disabled</a>
  84. </li>
  85. </ul>
  86. ```
  87. ## Pills
  88. For a pill-shaped navigation style, use the `.nav-pills` class. This is a great choice for a sleek, modern look, especially in interactive UI components.
  89. ```html example centered
  90. <ul class="nav nav-pills">
  91. <li class="nav-item">
  92. <a class="nav-link active" aria-current="page" href="#">Active</a>
  93. </li>
  94. <li class="nav-item">
  95. <a class="nav-link" href="#">Link</a>
  96. </li>
  97. <li class="nav-item">
  98. <a class="nav-link" href="#">Link</a>
  99. </li>
  100. <li class="nav-item">
  101. <a class="nav-link disabled" aria-disabled="true">Disabled</a>
  102. </li>
  103. </ul>
  104. ```
  105. ## Underline
  106. To create a navigation bar with an underline effect for active links, use the `.nav-underline` class. This provides a clean and minimalistic style.
  107. ```html example centered
  108. <ul class="nav nav-underline">
  109. <li class="nav-item">
  110. <a class="nav-link active" aria-current="page" href="#">Active</a>
  111. </li>
  112. <li class="nav-item">
  113. <a class="nav-link" href="#">Link</a>
  114. </li>
  115. <li class="nav-item">
  116. <a class="nav-link" href="#">Link</a>
  117. </li>
  118. <li class="nav-item">
  119. <a class="nav-link disabled" aria-disabled="true">Disabled</a>
  120. </li>
  121. </ul>
  122. ```
  123. ## Tabs with Dropdown
  124. You can enhance tabs by adding dropdown menus using the `.dropdown` class inside a `.nav-tabs` structure. This allows for additional options under a single tab, improving the navigation experience.
  125. ```html
  126. <ul class="nav nav-tabs">
  127. ...
  128. <li class="nav-item dropdown">
  129. <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</a>
  130. <ul class="dropdown-menu">
  131. ...
  132. </ul>
  133. </li>
  134. ...
  135. </ul>
  136. ```
  137. Example below shows how tabs with dropdown menus are displayed.
  138. ```html example centered height="15rem"
  139. <ul class="nav nav-tabs">
  140. <li class="nav-item">
  141. <a class="nav-link active" aria-current="page" href="#">Active</a>
  142. </li>
  143. <li class="nav-item dropdown">
  144. <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</a>
  145. <ul class="dropdown-menu">
  146. <li><a class="dropdown-item" href="#">Action</a></li>
  147. <li><a class="dropdown-item" href="#">Another action</a></li>
  148. <li><a class="dropdown-item" href="#">Something else here</a></li>
  149. <li><hr class="dropdown-divider"></li>
  150. <li><a class="dropdown-item" href="#">Separated link</a></li>
  151. </ul>
  152. </li>
  153. <li class="nav-item">
  154. <a class="nav-link" href="#">Link</a>
  155. </li>
  156. <li class="nav-item">
  157. <a class="nav-link disabled" aria-disabled="true">Disabled</a>
  158. </li>
  159. </ul>
  160. ```