搜索

首页  >  问答  >  正文

限制折叠手风琴段的高度 Bootstrap 5 Vue3

我正在使用 Vue3 和 bootstrap 5 构建一个网络应用程序。但我认为这个问题只涉及 bootstrap。我想要做的是限制折叠的手风琴段的高度,这样当其内容很长时,它不会将其他段踢得太低。

我尝试的是将 max-height 和 Overflow: auto 添加到类 .collapsing 中,并且我已经将“collapsing”添加到手风琴的类中,但随后手风琴滚动到该高度,一秒钟后跳转到完全展开。在 node_modules bootstrap 文件夹中,我查看了 _accordion.scss 并将“overflow-anchor”更改为 auto,但没有任何更改。

.collapsing {
  max-height: 100px !important;
  overflow: auto !important;
}

在这个示例文件中,我只是从 bootstrap 中获取了手风琴示例(在“Flush”下),所以我的 vue 文件如下所示:

<template>
  <div class="accordion accordion-flush" id="accordionFlushExample">
    <div class="accordion-item">
      <h2 class="accordion-header" id="flush-headingOne">
        <button
          class="accordion-button collapsed"
          type="button"
          data-bs-toggle="collapse"
          data-bs-target="#flush-collapseOne"
          aria-expanded="false"
          aria-controls="flush-collapseOne"
        >
          Accordion Item #1
        </button>
      </h2>
      <div
        id="flush-collapseOne"
        class="accordion-collapse collapse"
        aria-labelledby="flush-headingOne"
        data-bs-parent="#accordionFlushExample"
      >
        <div class="accordion-body">
          Placeholder<br />this must be long <br />this must be long <br />this
          must be long <br />this must be long <br />this must be long
          <br />this must be long <br />this must be long <br />this must be
          long <br />this must be long(thats what she said) <br />
        </div>
      </div>
    </div>
    <div class="accordion-item">
      <h2 class="accordion-header" id="flush-headingTwo">
        <button
          class="accordion-button collapsed"
          type="button"
          data-bs-toggle="collapse"
          data-bs-target="#flush-collapseTwo"
          aria-expanded="false"
          aria-controls="flush-collapseTwo"
        >
          Accordion Item #2
        </button>
      </h2>
      <div
        id="flush-collapseTwo"
        class="accordion-collapse collapse"
        aria-labelledby="flush-headingTwo"
        data-bs-parent="#accordionFlushExample"
      >
        <div class="accordion-body">
          Placeholder content for this accordion, which is intended to
          demonstrate the <code>.accordion-flush</code> class. This is the
          second item's accordion body. Let's imagine this being filled with
          some actual content.
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "stackoverflowquestion",
};
</script>

<style>
.collapsing {
  max-height: 100px !important;
  overflow: auto !important;
}
</style>

有什么想法吗?谢谢

P粉111227898P粉111227898232 天前469

全部回复(1)我来回复

  • P粉639667504

    P粉6396675042024-04-01 16:37:10

    找到了! 你必须把类放在手风琴体中。 所以首先定义一个类,例如

    .restrict-collapsing {
      max-height: 100px !important;
      overflow: auto !important;
    }

    然后在与 Accordion-body 相同的括号内调用它

    回复
    0
  • 取消回复