建立預設引導導航欄


在引導中遵循以下給定的步驟以建立預設導航欄 −

  • 將類 .navbar、.navbar-default 新增到 <nav> 標記中。
  • 為上面的元素新增 role = "navigation" 以幫助實現可訪問性。
  • 將頭部類 .navbar-header 新增到 <div> 元素。包含具有類 navbar-brand 的 <a> 元素。這會使文字變為稍大一些的號。
  • 若要嚮導航欄中新增連結,只需新增具有類 .nav、.navbar-nav 的無序列表。

可以嘗試執行以下程式碼以建立預設導航欄 −

示例

即時演示

<!DOCTYPE html>
<html>
   <head>
      <title>Bootstrap Example</title>
      <link href = "/bootstrap/css/bootstrap.min.css" rel = "stylesheet">
      <script src = "/scripts/jquery.min.js"></script>
      <script src = "/bootstrap/js/bootstrap.min.js"></script>
   </head>
   <body style = "background: #F5CBA7;">
      <nav class = "navbar navbar-default" role = "navigation">
         <div class = "navbar-header">
            <a class = "navbar-brand" href = "#">Cars</a>
         </div>
         <div>
            <ul class = "nav navbar-nav">
               <li class = "active"><a href = "#">BMW</a></li>
               <li><a href = "#">Audi</a></li>
               <li class = "dropdown">
               <a href = "#" class = "dropdown-toggle" data-toggle = "dropdown">
                  SUV
                  <b class = "caret"></b>
               </a>
               <ul class = "dropdown-menu">
                  <li><a href = "#">Creta</a></li>
                  <li><a href = "#">Scorpio</a></li>
               </ul>
               </li>
            </ul>
         </div>
      </nav>
   </body>
</html>

更新於: 12-Jun-2020

470 次瀏覽

開啟你的職業生涯

完成課程即可獲得認證

開始
廣告
© . All rights reserved.