html - 可滚动 ol 之后和之前
问题描述
我的 ol 上有我想为其位置设置动画的边框,但它们会随着内容滚动。有没有办法在不引入另一个节点的情况下修复它们?
div{
height: 100vh;
width: 30%;
}
ol{
height: 60%;
width: 100%;
overflow-y: scroll;
position: relative;
}
ol::before,
ol::after{
content: '';
height: 5px;
background: red;
width: 100%;
position: absolute;
}
ol::after{
bottom: 0;
}
li{
height: 300%;
}
<div>
<ol>
<li/>
</ol>
</div>
解决方案
可能的解决方案:将相对位置移动到先前的祖先
元素的位置position: absolute
最终是相对于最近的祖先的位置而不是静态的。如果我们有ol
未定义的位置,而是将其父级(div)设置为position: relative
它将绝对定位排除在 ol 的滚动行为之外......那么,伪元素的顶部和/或底部值取决于div/parent 而不是 ol 本身,所以相应地调整底部值。在这种情况下,它将是底部:40%,以抵消您定义为 60% 的 ol 的高度。
div {
height: 100vh;
width: 30%;
position: relative;
}
ol {
height: 60%;
width: 100%;
overflow-y: scroll;
}
ol::before,
ol::after {
content: '';
height: 5px;
background: red;
width: 100%;
position: absolute;
}
ol::after {
bottom: 40%;
}
li {
height: 300%;
}
<div>
<ol>
<li/>
</ol>
</div>
我不太确定这是否是您正在寻找的东西,我将根据需要编辑我的答案以澄清任何事情。我也会尝试尽快更新一些参考资料。
推荐阅读
- javascript - 图像到粒子过渡滚动
- android - 我正在使用 Intent.ACTION_OPEN_DOCUMENT_TREE 作为 location 。它是否需要 WRITE_EXTERNAL_STORAGE 或任何其他存储权限?
- visual-studio-code - 如何配置 vscode 终端命令行提示颜色?
- html - 在单词之间的空白处换行后更改字体大小
- python - Python JSON AttributeError:“str”对象没有属性“read”
- java - Spring Boot Rest Controller - 路由选择
- c++ - 非类类型错误
- python - 导入模块,“没有名为 x 的模块”,即使我有它
- android - 如何在没有组装调试错误的情况下运行第一个颤振演示应用程序
- javascript - 使用 classNames 和 styled 样式化 JSON Schema Form