html - 一个子 div 必须溢出另一个不能
问题描述
这里红色框是没有设置任何溢出属性的父 div。橙色和灰色的盒子是它的孩子。我想知道的是其中一个孩子是否有可能溢出另一个孩子?
.rootdiv {
width: 300px;
height: 300px;
background: red;
border: solid;
position: relative;
overflow: hidden;
}
.rootdiv .not-overflow {
border: dashed;
background: orange;
position: relative;
left: 20px;
}
.rootdiv .must-overflow {
border: dashed;
background: gray;
position: relative;
top: 20px;
left: 20px;
}
<div class="rootdiv">
<div class="not-overflow">
This must get chopped.
</div>
<div class="must-overflow">
This must overflow.
</div>
</div>
解决方案
我为 main 添加了溢出,<div>
并用于position:absolute
应该.must-overflow
溢出:
.rootdiv {
width: 300px;
height: 300px;
background: red;
border: solid;
overflow: hidden;
}
.rootdiv .not-overflow {
border: dashed;
background: orange;
position: relative;
left: 20px;
}
.rootdiv .must-overflow {
border: dashed;
background: gray;
position: absolute ;
top: 50px;
left: 30px;
width: 400px;
}
<div class="rootdiv">
<div class="not-overflow">
This must get chopped.
</div>
<div class="must-overflow">
This must overflow.
</div>
</div>
推荐阅读
- python - 如何使用 ELPY 进行自动完成工作?
- reactjs - 如何使用反应组件功能维护状态和“this”
- mingw-w64 - MSYS2-Mingw64 的 Insight 调试器编译器错误
- asp.net - 如何使用 Vue cli 将 Vue 项目添加到现有的 asp.net 4.6 Webforms 项目
- types - 根据模式匹配中的字符串输入返回不同的鉴别联合状态(F#)
- java - Java 字符串是否有效检查
- javascript - 获取从solidity到reactjs应用程序的文件列表
- python - 如何将列表转换为某些键缺少值的字典?
- java - 使用 StringReader 中的 read 方法
- java - 如何存储二维字符串数组(java)