如何在bootstrap 4中使打开的折叠头粘上?

mlnl4t2r  于 2022-12-07  发布在  Bootstrap
关注(0)|答案(1)|浏览(148)

有一个BS4折叠式,希望在用户向下滚动时将打开的标题保持在顶部,因此折叠式打开的标题的粘滞行为
实际方法不起作用:

#accordion .card-header BUTTON:not(.collapsed) {
    position: -webkit-sticky; /* Safari */
    position: sticky;
    top: 0;
}

页眉保持在屏幕上不可见
代码:

<style>
#accordion .card-header BUTTON:not(.collapsed) {
    position: -webkit-sticky; /* Safari */
    position: sticky;
    top: 0;
}
</style>

<div id="accordion" class="groups">
    <div class="card">
        <div class="card-header d-block d-md-none m-0 p-0">
            <h2 class="mb-0">
                <button
                    class="btn btn-link btn-block p-2"
                    data-toggle="collapse"
                    data-target="'#group-1"
                    aria-controls="'#group-1"
                    >title</button>
            </h2>
        </div>

        <div id="group-1" class="collapse" aria-labelledby="headingOne" data-parent="#accordion">
            ...
        </div>
    </div>
</div>
6tr1vspr

6tr1vspr1#

通过给出z-index来尝试:1000;在css中为#accordion .card-header BUTTON:不(.折叠)

相关问题