如何解决伪元素卡在父母的溢出中
在以下示例中,红色伪元素在父元素中创建水平滚动条,即使伪元素是 position: absolute
而父元素是 position: relative
.sidebar {
height: 100vh;
width: 300px;
position: relative;
background: grey;
overflow: auto;
overflow-x: visible;
}
.sidebar::after {
content: '';
position: absolute;
top: 0;
right: -40px;
width: 40px;
height: 40px;
background: red;
z-index: 1;
}
.content-block {
height: 200px;
width: 50%;
background: #0000ff;
margin-bottom: 5px;
}
<div class="sidebar">
<div class="content-block"></div>
<div class="content-block"></div>
<div class="content-block"></div>
<div class="content-block"></div>
<div class="content-block"></div>
</div>
这就是我希望实现的目标,除了蓝色框仍应在 .sidebar
内滚动:
- 红色伪元素应该在
.sidebar
的右侧可见 - 蓝色的
.content-block
元素应该在.sidebar
内滚动
我还没有找到干净的方法来实现这两个..
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。