css bootstrap5菜单图标在页面中不起作用

yi0zb3m4  于 2023-02-26  发布在  Bootstrap
关注(0)|答案(2)|浏览(305)

我的菜单图标不工作时,用户在移动终端上,它也不工作时,我检查页面,并尝试运行响应设备上的页面.我怎样才能解决这个问题,以便当用户访问页面时,他/她可以点击菜单图标,并看到我的导航项目?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Home</title>

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" 
    rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" 
    crossorigin="anonymous">
  </head>
  <style>
    .navbar-brand h1{
      font: small-caps bolder 50px/1 sens-serif;
      color: dodgerblue;
    }

    h2{
      font: italic 1.2rem "Fira Sans" sens-serif;
      color: black;
    }
  </style>
<body>
  <nav class="navbar navbar-expand-lg navbar-light bg-light">
    <div class="container">
      <a class="navbar-brand" href="#"><h1>Pondadb</h1></a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
      <ul class="navbar-nav ms-auto">
        <li class="nav-item active">
          <a class="btn btn-success mx-lg-2 mx-0 my-lg-0 my-2" href="{% url 'About' %}">About</a>
        </li>
        <li class="nav-item">
          <a class="btn btn-success mx-lg-2 mx-0 my-lg-0 my-2" href="{% url 'Register' %}">Register</a>
        </li>
        <li class="nav-item">
          <a class="btn btn-success mx-lg-2 mx-0 my-lg-0 my-2" href="#">Pricing</a>
        </li>
      </ul>
    </div>
      </div>
  </nav>
  <br>
            <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js" integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.min.js" integrity="sha384-mQ93GR66B00ZXjt0YO5KlohRA5SY2XofN4zfuZxLkoj1gXtW8ANNCe9d5Y3eG5eD" crossorigin="anonymous"></script>
</body>
</html>
cclgggtu

cclgggtu1#

所有JavaScript插件的数据属性现在都有命名空间,以帮助区分Bootstrap功能与第三方和您自己的代码。例如,我们使用data-bs-toggle代替data-toggle
https://getbootstrap.com/docs/5.0/migration/#javascript

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Home</title>

  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
</head>
<style>
  .navbar-brand h1 {
    font: small-caps bolder 50px/1 sens-serif;
    color: dodgerblue;
  }
  
  h2 {
    font: italic 1.2rem "Fira Sans" sens-serif;
    color: black;
  }
</style>

<body>
  <nav class="navbar navbar-expand-lg navbar-light bg-light">
    <div class="container">
      <a class="navbar-brand" href="#">
        <h1>Pondadb</h1>
      </a>
      <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
      <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav ms-auto">
          <li class="nav-item active">
            <a class="btn btn-success mx-lg-2 mx-0 my-lg-0 my-2" href="{% url 'About' %}">About</a>
          </li>
          <li class="nav-item">
            <a class="btn btn-success mx-lg-2 mx-0 my-lg-0 my-2" href="{% url 'Register' %}">Register</a>
          </li>
          <li class="nav-item">
            <a class="btn btn-success mx-lg-2 mx-0 my-lg-0 my-2" href="#">Pricing</a>
          </li>
        </ul>
      </div>
    </div>
  </nav>
  <br>
  <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js" integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.min.js" integrity="sha384-mQ93GR66B00ZXjt0YO5KlohRA5SY2XofN4zfuZxLkoj1gXtW8ANNCe9d5Y3eG5eD" crossorigin="anonymous"></script>
</body>

</html>
gopyfrb3

gopyfrb32#

Bootstrap 5更改了数据属性的命名,这些属性通常由使用JavaScript作为其功能一部分的组件使用。
以前,大多数依赖于某些JavaScript功能的组件都有以data-开头的数据属性。在Bootstrap 5中,这些组件的数据属性现在以data-bs开头,以便轻松命名Bootstrap属性。

  • 数据-BS-触发而不是数据-触发。
  • 数据BS目标而不是数据目标。
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Home</title>

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" 
    rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" 
    crossorigin="anonymous">
  </head>
  <style>
    .navbar-brand h1{
      font: small-caps bolder 50px/1 sens-serif;
      color: dodgerblue;
    }

    h2{
      font: italic 1.2rem "Fira Sans" sens-serif;
      color: black;
    }
  </style>
<body>
  <nav class="navbar navbar-expand-lg navbar-light bg-light">
    <div class="container">
      <a class="navbar-brand" href="#"><h1>Pondadb</h1></a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
      <ul class="navbar-nav ms-auto">
        <li class="nav-item active">
          <a class="btn btn-success mx-lg-2 mx-0 my-lg-0 my-2" href="{% url 'About' %}">About</a>
        </li>
        <li class="nav-item">
          <a class="btn btn-success mx-lg-2 mx-0 my-lg-0 my-2" href="{% url 'Register' %}">Register</a>
        </li>
        <li class="nav-item">
          <a class="btn btn-success mx-lg-2 mx-0 my-lg-0 my-2" href="#">Pricing</a>
        </li>
      </ul>
    </div>
      </div>
  </nav>
  <br>
            <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js" integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.min.js" integrity="sha384-mQ93GR66B00ZXjt0YO5KlohRA5SY2XofN4zfuZxLkoj1gXtW8ANNCe9d5Y3eG5eD" crossorigin="anonymous"></script>
</body>
</html>

相关问题