html - 溢出-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>
推荐阅读
- reactjs - Ant Design-仅在字段外单击时进行表单验证
- visual-studio-code - 如何创建自定义开发容器?
- image - 如何使用 Elfinder 上传图片
- visual-studio-code - 使用 WebStorm 后,VSCode 抛出“Cannot get /index.html”
- flutter - Flutter,如何设置 TabBar 高度?
- mysql - 我可以在 Aurora MySql 中杀死处于“查询结束”状态的进程吗
- scala - sbt 插件:添加一个非托管的 jar 文件
- outlook - Windows 桌面 Outlook 发送时加载项不起作用
- image - 无法在 Jenkins 管道文件中将分支名称标记为带有 docker 映像的标记名称
- kubernetes - 如何调试这个 Kubernetes coreDNS 错误?