DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> CSS入門知識 >> CSS詳解
用 DIV 解決固定寬度布局問題(中):HTML 與 CSS 實作
編輯:CSS詳解     

下面的 XHTML 標記會生成如圖 A 所示的頁面(為了簡潔,內容經過截短):

<body>
<div id="head">
<h1>header</h1>
</div>
<div id="columns">
<div id="side1">
<h3>side1</h3>
<ul>
<li>Let me not to the marriage of true minds</li>
<li>Admit impediments; love is not love</li>
<li>Which alters when it alteration finds</li>
<li>Or bends with the remover to remove</li>
<li>Oh, no, it is an ever fixed mark</li>
</ul>
</div>
<div id="content">
<h2>main content</h2>
<p>That looks on tempests... his height taken.</p>
<p>But bears it out... alteration finds.</p>
<p>Whose worth's unknown,... the remover to remove.</p>
</div>
<div id="side2">
<h3>side2</h3>
<ul>
<li>Let me not to the marriage of true minds</li>
<li>Admit impediments; love is not love</li>
<li>Which alters when it alteration finds</li>
</ul>
</div>
</div>
<div id="foot">
<h3>footer</h3>
<p>Or bends with... height taken.</p>
</div>
</body>

接著是將頁面設計為固定寬度布局的 CSS 程式碼:

body{
 font-family:Verdana,Arial,Helvetica,sans-serif;
 font-size:12px;
 margin:0px;
 padding:0px;
}
h2,h3{
 margin-top:0px;
 padding-top:0px;
}
DIV#head{
 position:absolute;
 width:750px;
 height:100px;
 left:0px;
 top:0px;
 background-color:#FFFF66;
}
DIV#columns{
 position:relative;
 width:750px;
 top:100px;
 background-color:#CCCCCC;
}
DIV#side1{
 position:absolute;
 width:150px;
 top:0px;
 left:0px;
 background-color:#FF6666;
}
DIV#content{
 position:relative;
 width:450px;
 top:0px;
 left:150px;
 background-color:#999999;
}
DIV#side2{
 position:absolute;
 width:150px;
 top:0px;
 left:600px;
 background-color:#00FF66;
}
DIV#foot{
 position:relative;
 width:750px;
 clear:both;
 margin-top:100px;
 background-color:#99FFFF;
}
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved