我需要创建以下结构:
[ 30px height ]
[ full height (100% - 30px) ]
是否可以仅使用 HTML5 + CSS3(跨浏览器)来实现这一点?此 DIV 不得重叠。
您可以通过绝对定位来实现这一点,而无需使用实验性且未被广泛支持 calc
的功能,以下适用于自 1999 年以来的每个浏览器:
<div id="root">
<div id="top"></div>
<div id="rest"></div>
</div>
#root {
height:300px;
width:300px;
background:blue;
position:relative;
}
#top {
height:24px;
position:absolute;
background:green;
border:3px solid maroon;
width:100%;
}
#rest {
border:3px solid yellow;
position:absolute;
width:100%;
top:30px;
bottom:0;
background:red;
}