我需要相对于视口设置子高度。使用HTML:
<div class="parent">My divider
<div class="child">
Inside the div
</div>
</div>
和CSS:
.t1 {
background:#f00;
color:#fff;
}
.t2 {
background:#212121;
height:100vh;
}
http://jsfiddle.net/hr8sL/7646/
从示例中可以看出,总是有这么小的差距,因为它考虑了父级的整体高度。但是,我只需要孩子来填补&#34;其余的&#34;来自父母的视口。
我该怎么办?我尝试了很多其他的事情,但没有足够的结果
答案 0 :(得分:0)
我会像this那样做。
使用css calc()
函数,我们可以计算剩余高度。
body {
margin: 0;
/* This is used to reset any browser-default margins */
}
.t1 {
background: #f00;
color: #fff;
height: 20px;
}
.t2 {
background: #212121;
height: calc(100vh - 20px);
}
&#13;
<div class="t1">
My divider
</div>
<div class="t2">
Inside the div
</div>
&#13;