如何使红色div的高度等于父黄色div?绝对定位div父容器的高度
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div class="main">
<div class="left">
</div>
<div class="right">
</div>
</div>
</body>
</html>
CSS:
.main {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0px;
background-color: yellow;
overflow: auto;
}
.left {
background-color: orange;
position: absolute;
top: 0;
left: 0;
width: 200px;
height: 2000px;
}
.right {
background-color: orangered;
position: absolute;
top: 0;
left: 200px;
right: 0;
bottom: 0;
}
这里举例:http://jsbin.com/fafexulube/edit?html,css,output
更新:左div的高度不能改变,它有2000像素,显示它是高于其父母。
绝对需要你绝对定位一切吗?否则,您可以考虑各种解决方案,使用表格单元格,弹性盒等。 – Terry
它与领土...如果没有明显的解决方案,那么我可能会去与表格单元格。 – andriys