【发布时间】:2016-03-07 20:38:22
【问题描述】:
我正在尝试创建一个响应式 div,它有一个部分和旁边。父 div 占据 25% 的高度。并且子 div 必须占据其父容器的 80%。但是如果高度以 % 为单位,它们就不会占据。但是当高度以像素为单位时,它可以正常工作。谁能告诉我哪里出错了。 这是html
<div class="container">
<section>
This is supposed to be a section
</section>
<aside>
This is supposed to be aside
</aside>
</div>
这是CSS
.container{
width: 100%;
background: red;
height: 25%;
}
.container::before,
.container::after{
content: "";
display: table;
}
.container::after{
clear: both;
}
section{
float: left;
width: 40%;
height: 100%;
display: block;
}
aside{
float: right;
width: 40%;
height: 80%;
}
section, aside{
background: green;
border-radius: 6px;
margin: 5%;
}
【问题讨论】:
-
没有继承自
html或body的高度。要么给它们一个特定的高度(可以是百分比),要么使用视口单位。 stackoverflow.com/q/8262852/3168107
标签: html css responsive-design