如何为引导导航栏添加功能

时间:2020-05-25 14:36:54

标签: javascript twitter-bootstrap

当我将页面调整为移动大小时,我有一个引导导航菜单,汉堡菜单不起作用,并且在控制台中出现错误,我该如何解决它

<nav class="navbar navbar-expand-lg navbar-light">
  <a href="home.html" class="navbar-brand ml-3 title-text">
    <img src="img/Owi_Arts Logo2.png" alt="logo">
  </a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarMenu" aria-controls="navbarMenu" aria-expanded="false" aria-label="Toggle Navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarMenu">
    <ul class="navbar-nav text-uppercase">
      <li class="nav-item active">
        <a href="home.html" class="nav-link">Home</a>
      </li>
      <li class="nav-item">
        <a href="about.html" class="nav-link">About Me</a>
      </li>
      <li class="nav-item">
        <a href="gallery.html" class="nav-link">Gallery</a>
      </li>
      <li class="nav-item">
        <a href="services.html" class="nav-link">Services</a>
      </li>
      <li class="nav-item">
        <a href="#Contact" class="nav-link">Contact</a>
      </li>
    </ul>
  </div>
  <div class="social-text">
    <a href="https://www.instagram.com/@owi_photography" target="_blank">
      <i class="fab fa-instagram"></i>
    </a>
  </div>
</nav>

1 个答案:

答案 0 :(得分:0)

像这样设置Bootstrap即可在您的代码中使用。但是,您的<div class="social-text">造成了整个.navbar的不正确间距,因此,如果您想直接从Bootstrap获得间距并调整其大小,则必须更改该间距

<head>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
</head>
<body>
  <nav class="navbar navbar-expand-lg navbar-light">
    <a href="home.html" class="navbar-brand ml-3 title-text">
      <img src="img/Owi_Arts Logo2.png" alt="logo">
    </a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarMenu"
    aria-controls="navbarMenu" aria-expanded="false" aria-label="Toggle Navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarMenu">
      <ul class="navbar-nav text-uppercase">
        <li class="nav-item active">
          <a href="home.html" class="nav-link">Home</a>
        </li>
        <li class="nav-item">
          <a href="about.html" class="nav-link">About Me</a>
        </li>
        <li class="nav-item">
          <a href="gallery.html" class="nav-link">Gallery</a>
        </li>
        <li class="nav-item">
          <a href="services.html" class="nav-link">Services</a>
        </li>
        <li class="nav-item">
          <a href="#Contact" class="nav-link">Contact</a>
        </li>
      </ul>
    </div>
    <div class="social-text">
      <a href="https://www.instagram.com/@owi_photography" target="_blank">
        <i class="fab fa-instagram"></i>
      </a>
    </div>
  </nav>


  <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
</body>