gpt4 book ai didi

html - 如何使用溢出自动阻止第一个 li 在 ul li 列表中滚动?

转载 作者:行者123 更新时间:2023-11-28 19:28:30 28 4
gpt4 key购买 nike

我制作了简单的 ul li 列表,其中 ul 具有特定的 max-height 和 overflow: auto 以便在有长列表可用时它可以滚动。但我正在尝试修复第一个 li 并想滚动所有其他 li。

.account-selector__listing.dropdown.is-open {
margin-bottom: 2rem;
position: relative;
max-height: 22rem;
overflow: auto;
}
<ul class="account-selector__listing ng-scope dropdown is-open">
<li class="account-selector__item ng-scope active dropdown">
//want to fix this li and dont want to scroll this
</li>
<li class="account-selector__item ng-scope active dropdown">
//some content
</li>
<li class="account-selector__item ng-scope active dropdown">
//should scroll
</li>
<li class="account-selector__item ng-scope active dropdown">
//should scroll
</li>
<li class="account-selector__item ng-scope active dropdown">
//should scroll
</li>
<li class="account-selector__item ng-scope active dropdown">
//should scroll
</li>
</ul>

CSS 中有什么可以修复第一个 li 并可以垂直滚动所有其他内容吗?像这样

enter image description here

最佳答案

如果您在 ul 周围创建一个容器元素,您可以使用 position 实现此效果。

  • 将容器元素设置为 position: relative 并为其提供顶部填充。
  • li:first-child设置为position: absolute
  • ul 设置为 position: static 以便 li:first-child 从容器元素而不是 获取其定位>ul

.ulOuter {
position: relative;
padding-top: 10px;
}

.account-selector__listing.dropdown.is-open {
margin-bottom: 2rem;
max-height: 120px;
overflow: auto;
position: static;
box-shadow: 0 0 3px inset #eeeeee;
}

.account-selector__listing.dropdown.is-open li:first-child {
position: absolute;
top: 0;
left: 0;
width: 100%;
}
<div class="ulOuter">
<ul class="account-selector__listing ng-scope dropdown is-open" >
<li class="account-selector__item ng-scope active dropdown">
//want to fix this li and dont want to scroll this
</li>
<li class="account-selector__item ng-scope active dropdown">
//some content
</li>
<li class="account-selector__item ng-scope active dropdown">
//should scroll
</li>
<li class="account-selector__item ng-scope active dropdown">
//should scroll
</li>
<li class="account-selector__item ng-scope active dropdown">
//should scroll
</li>
<li class="account-selector__item ng-scope active dropdown">
//should scroll
</li>
<li class="account-selector__item ng-scope active dropdown">
//should scroll
</li>
<li class="account-selector__item ng-scope active dropdown">
//should scroll
</li>
<li class="account-selector__item ng-scope active dropdown">
//should scroll
</li>
<li class="account-selector__item ng-scope active dropdown">
//should scroll
</li>
<li class="account-selector__item ng-scope active dropdown">
//should scroll
</li>
</ul>
</div>

关于html - 如何使用溢出自动阻止第一个 li 在 ul li 列表中滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55680019/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com