如何将粘性的手风琴标头通过打开的手风琴主体向前

发布于 2025-02-07 04:58:56 字数 970 浏览 2 评论 0原文

我目前有一个手风琴头,该标头已设置为位置粘性和前10PX,如下所示。 您可以在红色框中看到问题背后的蓝色手风琴头

我希望手风琴机构始终处于视口的顶部,在滚动时,手风琴机构在标题下方。

我将如何防止手风琴头和身体重叠?我尝试设置相对于手风琴头的设置位置,但这无效。我还使用了d没有起作用的z索引

.accordion-header.sticky {
position: -webkit-sticky;
position: sticky;
top: 10px;
}


<script type="text/template" id="accordion-item-template">
<div class="accordion-item">
    <h2 class="accordion-header sticky" id="headingOne">
        <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="###NAME##"><i class="bi bi-eye-slash ##VISIBLE##"></i>##TEXT##</button>
    </h2>
    <div id="##NAME##" class="accordion-collapse collapse" data-bs-parent="###PARENT##-accordion">
        <div class="accordion-body" id="##NAME##-accordion-body"></div>
    </div>
</div>

I currently have an accordion header that has been set as position sticky and top 10px as shown below.
You can see the blue accordion header behind the questions in the red box

You can see the blue accordion header behind the questions in the red box
However currently the content of the accordion body is appearing over the header that is set as sticky.

I would like the accordion body to be always at the top of the viewport with the accordion body being below the header when scrolling.

What way would I be able to prevent accordion header and body overlapping? I have tried setting the position relative to the accordion header but this hasnt worked. I have also using Z-Index which hasnt worked

.accordion-header.sticky {
position: -webkit-sticky;
position: sticky;
top: 10px;
}


<script type="text/template" id="accordion-item-template">
<div class="accordion-item">
    <h2 class="accordion-header sticky" id="headingOne">
        <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="###NAME##"><i class="bi bi-eye-slash ##VISIBLE##"></i>##TEXT##</button>
    </h2>
    <div id="##NAME##" class="accordion-collapse collapse" data-bs-parent="###PARENT##-accordion">
        <div class="accordion-body" id="##NAME##-accordion-body"></div>
    </div>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嗳卜坏 2025-02-14 04:58:56

为了将标头向前移到手风琴主体的顶部,使用以下班级可以使其看起来的预期。

.accordion-header.sticky {
position: -webkit-sticky;
position: sticky;
top: 0px;
z-index: 1;}

To bring the header forward over the top of the accordion body, using the following class has worked making it look how it is intended.

.accordion-header.sticky {
position: -webkit-sticky;
position: sticky;
top: 0px;
z-index: 1;}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文