html - 仅使用 CSS(无 JS)将相对定位的 div 内的元素与溢出自动重叠
问题描述
我试图用position relative
and重叠另一个 div 内的元素overflow auto
。我的目标是将此元素重叠在此父 div 上,保持父 div 的确切样式并仅使用CSS but no JS
.
HTML结构
<div class="parent" style="position: relative; width: 400px; height: 400px; background: red; overflow-x: auto;">
<div class="children" style="position: relative; width: 800px; height: 200px; background: green;">
<div class="element" style="position: absolute; width: 50px; height: 750px;"></div>
</div>
</div>
我需要这个element
div 与 div 重叠parent
。
我也分享codepen链接有一个想法,如果它可以在那里修改:Codepen Example
悬停时蓝色框 [元素 div ] 需要与所有父 div 重叠
希望我提供的信息是解释性的,如果需要更多信息,请告诉我。
更多简报:
What's happening
发生了什么
What's expecting
期待什么
HTML in codepen
.parent {
position: relative;
width: 400px;
height: 400px;
background: rgba(255, 0, 0, 0.75);
overflow-x: auto;
}
.children {
position: relative;
width: 800px;
height: 200px;
background: rgba(0, 255, 0, 0.75);
}
.children:last-child {
margin-top: 50px;
position: relative;
width: 800px;
height: 100px;
background: rgba(0, 255, 0, 0.75);
}
.element {
position: absolute;
width: 50px;
height: 50px;
background: rgba(0, 0, 255, 0.75);
transition: all ease-in-out 0.5s;
-webkit-transition: all ease-in-out 0.5s;
z-index: 100;
}
.element:hover {
height: 700px;
}
<div class="parent">
<div class="children">
<div class="element"></div>
</div>
<div class="children">
<div class="element"></div>
</div>
</div>
解决方案
推荐阅读
- php - 使用 WooCommerce 产品字幕插件的单个产品页面中未显示字幕
- selenium - RobotFrameWork:类名称更改如何将机器人导航到 2e TR 和 6e TC
- r - 将矩阵重塑为交替列的向量
- java - 当我在同一页面上有 15 个以上的按钮具有不同的 xpath 时,无法继续到下一个按钮
- php - 在 000webhost 中创建网站时遇到 PHP 错误
- javascript - 如何计算压缩对象的大小?
- apache-kafka - 如何使用 kafka.tools.JmxTool 访问 JMX 指标?
- javascript - 如何使用状态而不是参考来设置文本区域的选择?
- c# - 创建带有单选按钮的下拉菜单
- dbeaver - 在 DBeaver 中查看主键