萬盛學電腦網

 萬盛學電腦網 >> 網頁制作 >> DivCSS教程 >> DIV+CSS網頁設計常用布局代碼

DIV+CSS網頁設計常用布局代碼

單行一列

body{margin:0px;padding:0px;text-align:center;}
#content{margin-left:auto;margin-right:auto;width:400px;width:370px;}

兩行一列

body{margin:0px;padding:0px;text-align:center;}
#content-top{margin-left:auto;margin-right:auto;width:400px;width:370px;}
#content-end{margin-left:auto;margin-right:auto;width:400px;width:370px;}

三行一列

body{margin:0px;padding:0px;text-align:center;}
#content-top{margin-left:auto;margin-right:auto;width:400px;width:370px;}

#content-mid{margin-left:auto;margin-right:auto;width:400px;width:370px;}
#content-end{margin-left:auto;margin-right:auto;width:400px;width:370px;}

單行兩列

#bodycenter{width:700px;margin-right:auto;margin-left:auto;overflow:auto;}
#bodycenter#dv1{float:left;width:280px;}
#bodycenter#dv2{float:right;width:410px;}

兩行兩列

#header{width:700px;margin-right:auto;margin-left:auto;overflow:auto;}
#bodycenter{width:700px;margin-right:auto;margin-left:auto;overflow:auto;}


#bodycenter#dv1{float:left;width:280px;}
#bodycenter#dv2{float:right;width:410px;}

三行兩列

#header{width:700px;margin-right:auto;margin-left:auto;}
#bodycenter{width:700px;margin-right:auto;margin-left:auto;}
#bodycenter#dv1{float:left;width:280px;}
#bodycenter#dv2{float:right;width:410px;}
#footer{width:700px;margin-right:auto;margin-left:auto;overflow:auto;}
//www.qpsh.com

單行三列 絕對定位

#left{position:absolute;top:0px;left:0px;width:120px;}
#middle{margin:20px190px20px190px;}
#right{position:absolute;top:0px;right:0px;width:120px;}

float定位一
xhtml:

<divid="warp"><divid="column"><divid="column1">這裡是第一列</div><divid="column2">這裡是第二列</div><divclass="clear"></div></div><divid="column3">這裡是第三列</div><divclass="clear"></div></div>

CSS:

#wrap{width:100%;height:auto;}
#column{float:left;width:60%;}
#column1{float:left;width:30%;}
#column2{float:right;width:30%;}
#column3{float:right;width:40%;}
.clear{clear:both;}

float定位二
xhtml:
<divid="center"class="column"><h1>Thisisthemaincontent.</h1></div><divid="left"class="column"><h2>Thisistheleftsidebar.</h2></div><divid="right"class="column"><h2>Thisistherightsidebar.</h2></div>

CSS:

body{margin:0;padding-left:200px;padding-right:190px;min-width:240px;}
.column{position:relative;float:left;}
#center{width:100%;}
#left{width:180px;right:240px;margin-left:-100%;}
#right{width:130px;margin-right:-100%;}

兩行三列
xhtml:<divid="header">這裡是頂行</div><divid="warp"><divid="column"><divid="column1">這裡是第一列</div><divid="column2">這裡是第二列</div><divclass="clear"></div></P><P></div><divid="column3">這裡是第三列</div><divclass="clear"></div></div>

CSS:

#header{width:100%;height:auto;}
#wrap{width:100%;height:auto;}
#column{float:left;width:60%;}
#column1{float:left;width:30%;}
#column2{float:right;width:30%;}
#column3{float:right;width:40%;}
.clear{clear:both;}

三行三列
xhtml:
<divid="header">這裡是頂行</div><divid="warp"><divid="column"><divid="column1">這裡是第一列</div><divid="column2">這裡是第二列</div><divclass="clear"></div></div><divid="column3">這裡是第三列</div><divclass="clear"></div></div><divid="footer">這裡是底部一行</div>

CSS:

#header{width:100%;height:auto;}
#wrap{width:100%;height:auto;}
#column{float:left;width:60%;}
#column1{float:left;width:30%;}
#column2{float:right;width:30%;}
#column3{float:right;width:40%;}
.clear{clear:both;}
#footer{width:100%;height:auto;

copyright © 萬盛學電腦網 all rights reserved