【发布时间】:2013-11-03 22:54:26
【问题描述】:
我想要一个页眉高 120 像素,页脚高 120 像素的网页, 和一个主要内容,其最小高度为 600px,但当浏览器是 垂直拉伸超过 840px 高度(或用户缩小 Firefox 上的“控制减号”),我希望身体垂直伸展 填充所有可用空间减去页眉和页脚空间。
这是我尝试过的:
<header>This is the header.</header>
<div id="mainContent">This is the main content.</div>
<footer>This is the footer.</footer>
这是 CSS:
header { height: 120px; background: red; }
div#mainContent { min-height: 600px; height: 100%; background: green; }
footer { height: 120px; background: blue; }
完整代码如下:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style type="text/css">
header { height: 120px; background: red; }
div#mainContent { height: 100%; background: green; }
footer { height: 120px; background: blue; }
</style>
</head>
<body>
<header>This is the header.</header>
<div id="mainContent">This is the main content.</div>
<footer>This is the footer.</footer>
</body>
</html>
达到我想要的效果的正确方法是什么。
谢谢。
【问题讨论】:
标签: html css layout stretch stretching