需要帮助以在不滚动的情况下在父项上显示最里面的 div。 当子 div 显示: block 时,我不想在父 div 上滚动。 我无法删除 .divrelative{position:relative;}, 我有固定的父级高度。
.parent{background:#ccc; padding:10px; height:100px; overflow-y:auto;}
.divrelative{position:relative;}
.child{ background:#fff; width:80%; height:180px; border:1px solid #000; position:absolute; z-index:9999;}
<div class="parent">
<div class="divrelative">
<div class="child"></div>
</div>
</div>
最佳答案
在这种情况下,您谈到了“在父级之上”,如果您接受重叠,只需删除“overflow-y:auto
”规则即可。
.parent {
background: #ccc;
padding: 10px;
height: 100px;
}
.divrelative {
position: relative;
}
.child {
background: #fff;
width: 80%;
height: 180px;
border: 1px solid #000;
position: absolute;
z-index: 9999;
}
<div class="parent">
<div class="divrelative">
<div class="child"></div>
</div>
</div>
关于html - 如何解决这种与 div 位置相关的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28450964/