关键词搜索

源码搜索 ×
×

BootStrap笔记-导航

发布2022-01-24浏览843次

详情内容

运行截图如下:

源码如下:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>CN_TEST1</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  7. <!-- bootstrap css核心文件-->
  8. <link rel="stylesheet" href="bootstrap-4.4.1-dist/css/bootstrap.min.css">
  9. <!-- bootstrap使用到了jquery,需要提前引用-->
  10. <script src="js/jquery-3.5.1.min.js"></script>
  11. <!-- 弹窗、提示、下拉菜单-->
  12. <script src="bootstrap-4.4.1-dist/js/bootstrap.bundle.js"></script>
  13. <!-- bootstrap核心文件-->
  14. <script src="bootstrap-4.4.1-dist/js/bootstrap.min.js"></script>
  15. </head>
  16. <body>
  17. <div class="container-fluid">
  18. <ul class="nav">
  19. <li class="nav-item">
  20. <a class="nav-link" href="#">Link</a>
  21. </li>
  22. <li class="nav-item">
  23. <a class="nav-link" href="#">Link</a>
  24. </li>
  25. <li class="nav-item">
  26. <a class="nav-link" href="#">Link</a>
  27. </li>
  28. <li class="nav-item">
  29. <a class="nav-link disabled" href="#">Link</a>
  30. </li>
  31. </ul>
  32. <ul class="nav justify-content-center">
  33. <li class="nav-item">
  34. <a class="nav-link" href="#">Link</a>
  35. </li>
  36. <li class="nav-item">
  37. <a class="nav-link" href="#">Link</a>
  38. </li>
  39. <li class="nav-item">
  40. <a class="nav-link" href="#">Link</a>
  41. </li>
  42. <li class="nav-item">
  43. <a class="nav-link disabled" href="#">Link</a>
  44. </li>
  45. </ul>
  46. <ul class="nav justify-content-end">
  47. <li class="nav-item">
  48. <a class="nav-link" href="#">Link</a>
  49. </li>
  50. <li class="nav-item">
  51. <a class="nav-link" href="#">Link</a>
  52. </li>
  53. <li class="nav-item">
  54. <a class="nav-link" href="#">Link</a>
  55. </li>
  56. <li class="nav-item">
  57. <a class="nav-link disabled" href="#">Link</a>
  58. </li>
  59. </ul>
  60. <ul class="nav flex-column">
  61. <li class="nav-item">
  62. <a class="nav-link" href="#">Link</a>
  63. </li>
  64. <li class="nav-item">
  65. <a class="nav-link" href="#">Link</a>
  66. </li>
  67. <li class="nav-item">
  68. <a class="nav-link" href="#">Link</a>
  69. </li>
  70. <li class="nav-item">
  71. <a class="nav-link disabled" href="#">Link</a>
  72. </li>
  73. </ul>
  74. <!-- 左列的-->
  75. <ul class="nav flex-column">
  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" href="#">Link</a>
  84. </li>
  85. <li class="nav-item">
  86. <a class="nav-link disabled" href="#">Link</a>
  87. </li>
  88. </ul>
  89. <!-- 选项卡-->
  90. <ul class="nav nav-tabs">
  91. <li class="nav-item">
  92. <a class="nav-link" href="#">Link</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" href="#">Link</a>
  102. </li>
  103. </ul>
  104. <!-- 胶囊导航-->
  105. <ul class="nav nav-pills">
  106. <li class="nav-item">
  107. <a class="nav-link active" href="#">Link</a>
  108. </li>
  109. <li class="nav-item">
  110. <a class="nav-link" href="#">Link</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 disabled" href="#">Link</a>
  117. </li>
  118. </ul>
  119. <!-- 胶囊下拉菜单-->
  120. <ul class="nav nav-pills">
  121. <li class="nav-item">
  122. <a class="nav-link active" href="#">Link</a>
  123. </li>
  124. <li class="nav-item">
  125. <a class="nav-link" href="#">Link</a>
  126. </li>
  127. <li class="nav-item">
  128. <a class="nav-link" href="#">Link</a>
  129. </li>
  130. <li class="nav-item">
  131. <a class="nav-link disabled" href="#">Link</a>
  132. </li>
  133. <li class="nav-item dropdown">
  134. <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#">Dropdown</a>
  135. <div class="dropdown-menu">
  136. <a class="dropdown-item" href="#">Link 1</a>
  137. <a class="dropdown-item" href="#">Link 2</a>
  138. <a class="dropdown-item" href="#">Link 3</a>
  139. </div>
  140. </li>
  141. </ul>
  142. <!-- 选项卡-->
  143. <ul class="nav nav-tabs">
  144. <li class="nav-item">
  145. <a class="nav-link" href="#">Link</a>
  146. </li>
  147. <li class="nav-item">
  148. <a class="nav-link" href="#">Link</a>
  149. </li>
  150. <li class="nav-item">
  151. <a class="nav-link" href="#">Link</a>
  152. </li>
  153. <li class="nav-item">
  154. <a class="nav-link disabled" href="#">Link</a>
  155. </li>
  156. <li class="nav-item dropdown">
  157. <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#">Dropdown</a>
  158. <div class="dropdown-menu">
  159. <a class="dropdown-item" href="#">Link 1</a>
  160. <a class="dropdown-item" href="#">Link 2</a>
  161. <a class="dropdown-item" href="#">Link 3</a>
  162. </div>
  163. </li>
  164. </ul>
  165. <!-- 动态选项卡-->
  166. <ul class="nav nav-tabs">
  167. <li class="nav-item">
  168. <a class="nav-link" href="#">Link</a>
  169. </li>
  170. <li class="nav-item">
  171. <a class="nav-link" href="#">Link</a>
  172. </li>
  173. <li class="nav-item">
  174. <a class="nav-link" href="#">Link</a>
  175. </li>
  176. <li class="nav-item">
  177. <a class="nav-link disabled" href="#">Link</a>
  178. </li>
  179. <div class="tab-content">
  180. <div class="tab-pane active container" id="home">...</div>
  181. <div class="tab-pane container" id="menu">...</div>
  182. <div class="tab-pane container" id="menu2">...</div>
  183. </div>
  184. </ul>
  185. <ul class="nav nav-pills">
  186. <li class="nav-item">
  187. <a class="nav-link active" href="#">Link</a>
  188. </li>
  189. <li class="nav-item">
  190. <a class="nav-link" href="#">Link</a>
  191. </li>
  192. <li class="nav-item">
  193. <a class="nav-link" href="#">Link</a>
  194. </li>
  195. <li class="nav-item">
  196. <a class="nav-link disabled" href="#">Link</a>
  197. </li>
  198. <li class="nav-item dropdown">
  199. <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#">Dropdown</a>
  200. <div class="dropdown-menu">
  201. <a class="dropdown-item" href="#">Link 1</a>
  202. <a class="dropdown-item" href="#">Link 2</a>
  203. <a class="dropdown-item" href="#">Link 3</a>
  204. </div>
  205. </li>
  206. </ul>
  207. </div>
  208. </body>
  209. </html>

解释:

①在ul元素上添加nav类,li上添加nav-item就可以实现导航的功能;

②ul上添加nav类后还可以添加justify-content-center和justify-content-end,设置导航为居中和右对齐;

③flex-column用于创建垂直导航;

④ul上添加nav类后,再添加nav-tabs就是选项卡了,可以使用li中可以添加active作为选中。

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载