css - 仅当单击箭头时引导 Accordion 才展开

标签 css bootstrap-5

我正在使用 Bootstrap 5 来设计我的网站,我想知道是否有任何方法可以仅在单击右侧箭头时展开 Accordion 。默认行为是整个按钮是可展开的,我想简单地更改它。

以下是文档中的代码,仅供引用:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.0.2/css/bootstrap.min.css">

<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>

<script type = "text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/js/bootstrap.min.js"></script>

最佳答案

.accordion-button {
    pointer-events: none;
}

.accordion-button::after {
    pointer-events: all;
}

将此代码添加到您的 CSS 中。

关于css - 仅当单击箭头时引导 Accordion 才展开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72186023/

相关文章:

html - 如何在 Bootstrap 5 中将文字环绕图像

html - Firefox 鼠标悬停的 CSS 翻转问题

css - 将 Bootstrap 网格重新排列为不同数量的列,而无需重复代码

html - btn-group 下拉菜单不起作用,但 nav-item 下拉菜单在带有 Bootstrap 的 Angular 中起作用

jquery - Bootstrap : Control multiple tab panels with single tab nav

jquery - 使用 jQuery 和 Bootstrap 可重复使用的下拉菜单

css - 如何使用 flexbox 来创建砌体布局?

列表中每个第二个 div 的 CSS 样式

iphone - CSS 媒体查询无法在 iPhone 4 上正确加载

javascript - Bootstrap 5 : Event stopPropagation() or stopImmediatePropagation() is not working in According