如何解决溢出-x:自动且位置:绝对
带有position: absolute
的元素出现故障
而不是这样:
您可以在codepen上编辑以下代码。
.container {
margin: auto;
width: 700px;
height: 300px;
background: lightblue;
overflow-x: auto;
position: relative;
}
.child {
width: 50px;
height: 300px;
position: absolute;
top: 100%;
background: red;
}
<div class="container">
<div class="child"></div>
</div>
解决方法
添加绝对定位的子元素会使父对象溢出时,父对象上的overflow-x: auto
设置扩展的高度。删除它以获得与第二张图片一样的结果。
.container {
margin: auto;
width: 700px;
height: 300px;
background: lightblue;
position: relative;
}
.child {
width: 50px;
height: 300px;
position: absolute;
top: 100%;
background: red;
}
<div class="container">
<div class="child"></div>
</div>
,
尝试一下:
.child {
width: 50px;
height: 300px;
position: absolute;
bottom: 0;
background: red;
}
我认为这就是您所需要的
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。