關于width 設置px 或者%的問題
第5章 用HTML+CSS實現復雜結構的混合布局
5-3 編程挑戰
中:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>混合布局編程挑戰</title>
<style type="text/css">
body{ margin:0; padding:0; font-size:30px; color:#fff}
.top{height:100px;background:gray;}
.main{height:600px;background:red;}
.right{height:600px;background:green;margin:0 0 0 210px;}
.left{height:600px;width:200px;background:blue;position:absolute;top:100px;left:0;}
.foot{height:50px;background:orange;}
</style>
</head>
<body>
<div class="top">top</div>
<div class="main">
? ? <div class="right">right</div>
? ? <div class="left">left</div>
</div>
<div class="foot">foot</div>
</body>
</html>
為什么不能寫成height:100%;?
2016-08-10
如果父元素是body,這個元素的高度一般都不會使用100%,這樣會高度無限制的;也就是說滾輪滾不到底,除非父元素的高度被限制,這樣的話即使設置100%,最多也就和父元素高度一樣,前提不能有滾動條。個人理解,不一定對,僅供參考。
2016-08-10
<div class="main">
? ? <div class="right">right</div>
? ? <div class="left">left</div>
</div>
在這里,父級元素是main,
.main{height:600px;background:red;}
main的高度被限制在了600px