在 Bootstrap 导航栏中添加按钮

bootstrapweb developmentcss framework更新于 2026/2/11 18:20:17

使用 .navbar-btn 类为 <button> 元素添加按钮。您可以尝试运行以下代码,将按钮添加到导航栏

示例

<!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>
      <nav class = "navbar navbar-default" role = "navigation" style="background: red;color:white;">
         <div class = "navbar-header">
            <a class = "navbar-brand" href = "#">Example</a>
         </div>
         <div>
            <form class = "navbar-form navbar-left" role = "search">
               <div class = "form-group">
                  <input type = "text" class = "form-control" placeholder = "Search here...">
               </div>
               <button type = "submit" class = "btn btn-default">Submit Button</button>
            </form>
            <button type = "button" class = "btn btn-default navbar-btn">Navbar Button</button>
         </div>
      </nav>
   </body>
</html>

相关文章