布局时,当父元素设置定值时,子元素没有出现问题;当父元素设置百分比或者给页面设置高度定值时,子元素无法设置百分比。耦合度太高了:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>圣杯布局</title>
<style>
body {
min-width: 1000px;
margin: 0;
}
header,footer {
width: 600px;
height: 50px;
background-color: cyan;
margin: 0 auto;
border: 10px solid #ffff00;
text-align: center;
}
.col {
width: 600px;
height: 500px;
border:10px solid #000000;
margin: 0 auto;
text-align: center;
}
.left {
width: 100px;
height: 500px;
background-color: lime;
float: left;
margin-top: -500px;
}
.center {
height: 500px;
background-color: mediumorchid;
box-sizing: border-box;
padding: 0 100px;
}
.right {
width: 100px;
height: 500px;
background-color: red;
float: right;
margin-top: -500px;
}
</style>
</head>
<body>
<header>我是顶部</header>
<div class="col">
<div class="center">我是中间</div>
<div class="left">我是左部</div>
<div class="right">我是右部</div>
</div>
<footer>我是底部</footer>
</body>
</html>
一般header和footer 是高度固定的,屏幕充满的话可以选择绝对定位,子元素就可以使用百分比了,楼主只给了固定高度的样式,没有给使用百分比设置的样式,怎么修改还是要看具体情况