【问题标题】:Bootstrap accordion won't expand on one pageBootstrap 手风琴不会在一页上展开
【发布时间】:2021-12-22 12:11:33
【问题描述】:

在我的索引页面上,我使用了来自 getbootstrap.com 的示例代码,现在我想在同一站点的不同页面上再次使用它。它显示得很好,但没有响应并且不会展开/折叠。

两个页面的标题内容完全相同 - 字面意思是复制/粘贴。我不是编码方面的专业人士 - 有什么想法吗?谢谢!

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
    <link rel="stylesheet" href="stylesheet-search.css">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400&display=swap" rel="stylesheet">
    <title></title>
  </head>
  <body>
    <nav class="navbar navbar-expand-lg navbar-white bg-white">
      <div class="container-fluid">
        <a class="navbar-brand" href="#">
          <img src="images/white_logo_color_background.jpg" alt="" width="170" height="50" class="d-inline-block align-text-top">
        </a>
        <ul class="navbar-nav navbar-text">
          <li class="nav=item">
            <a class="nav-link active text-secondary fontstyles" area-current="page" href="index.php">Home</a>
          </li>
          <li class="nav=item">
            <a class="nav-link text-secondary fontstyles" href="searchreziworks.php"><strong>Search ReziWorks</strong></a>
          </li>
          <li class="nav=item">
            <a class="nav-link text-secondary fontstyles" href="createprofile.php">Be a prototype user</a>
          </li>
          <li class="nav=item">
            <a class="nav-link text-dark fontstyles" href="becomepartner.php">Become a partner company</a>
          </li>
        </ul>
      </div>
    </nav>
    <br><br><br>
    <div class="accordion" id="accordionExample">
      <div class="accordion-item">
        <h2 class="accordion-header" id="headingOne">
          <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
            Accordion Item #1
          </button>
        </h2>
        <div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
          <div class="accordion-body">
            <strong>This is the first item's accordion body.</strong> It is shown by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
          </div>
        </div>
      </div>
      <div class="accordion-item">
        <h2 class="accordion-header" id="headingTwo">
          <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
            Accordion Item #2
          </button>
        </h2>
        <div id="collapseTwo" class="accordion-collapse collapse" aria-labelledby="headingTwo" data-bs-parent="#accordionExample">
          <div class="accordion-body">
            <strong>This is the second item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
          </div>
        </div>
      </div>
      <div class="accordion-item">
        <h2 class="accordion-header" id="headingThree">
          <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
            Accordion Item #3
          </button>
        </h2>
        <div id="collapseThree" class="accordion-collapse collapse" aria-labelledby="headingThree" data-bs-parent="#accordionExample">
          <div class="accordion-body">
            <strong>This is the third item's accordion body.</strong> It is hidden by default, until the collapse plugin adds the appropriate classes that we use to style each element. These classes control the overall appearance, as well as the showing and hiding via CSS transitions. You can modify any of this with custom CSS or overriding our default variables. It's also worth noting that just about any HTML can go within the <code>.accordion-body</code>, though the transition does limit overflow.
          </div>
        </div>
      </div>
    </div>

</body>
</html>

【问题讨论】:

    标签: bootstrap-5 bootstrap-accordion


    【解决方案1】:

    找到答案。我忘了把 JS/popper 脚本放在页面末尾。

    【讨论】:

    • 附注 Chris,如果您使用 Bootstrap 5 Bundle JS,则包含 Popper。您在页面中调用 Bootstrap 的方式假定没有 Popper,然后您添加了 popper。您可以通过为 Bootstrap Bundle 添加一行来获得全部内容。这一切都在文档中。顺便说一句,在挖掘答案方面做得很好。
    猜你喜欢
    • 2019-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-23
    • 2017-01-21
    • 1970-01-01
    • 2020-01-25
    • 1970-01-01
    相关资源
    最近更新 更多