javascript - 使 div 的高度与其中的绝对 div 相同
问题描述
我有一个 div(具有相对位置),里面有两个 div。其中一个具有绝对定位,我注意到它超出了 div 的父级边距。
我想让 div 父级(以及其他非绝对定位 div)的高度与绝对定位 div 的高度相同。
基本上,我希望容器 div 及其内部的所有 div 将它们的高度调整为所采用的最高高度。
你能帮我理解怎么做吗?
.container {
width: 100vw;
height: auto;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
margin: 0;
background-color: blue;
}
.element {
width: 50%;
padding: 50px 150px 90px 50px;
box-sizing: border-box;
font-size: 30px;
position: relative;
font-family: 'helvetica','arial',sans-serif;
}
#element-1 {
background-color: beige;
}
#element-2 {
background-color: darkGreen;
color: white;
position: absolute;
right: 0;
}
<div class="container">
<div class="element" id="element-1">
<h1>Lorem Ipsum Dolor</h1>
</div>
<div class="element" id="element-2">
<h1>Lorem ipsum dolor sit amet</h1>
</div>
</div>
解决方案
推荐阅读
- javascript - Which Event.target Property Should I Use?
- angular - 如何在Angular组件中向传单地图添加标记
- sql - 使用案例语句插入
- java - 不使用 if 就抛出异常 - Java
- python - QThreadPool 是按顺序运行而不是并行运行,是什么导致我的代码线程不并行运行?
- javascript - 折叠标题与滚动时的动态高度
- javascript - 在统一开始使用 javaScript 进行游戏开发之前,我是否需要了解任何其他语言?
- swift-playground - 如何在操场上故意退出?
- javascript - 我如何使用 .map()、.reduce() 和 .filter() 而不是 forEach 来使我的代码简洁以免脆弱?
- android - 如何将数据从 Sqlite 迁移到 Realm