DIV+CSS最常⽤的⽹页布局代码11例。
div css布局不同于table布局,它主要是按列来计算,⽽table是嵌套实现。这⾥列举了最常见的⼏种布局代码:单⾏⼀列
CSS Code复制内容到剪贴板
body { margin: 0px; padding: 0px; text-align: center; }
#content { margin-left:auto; margin-right:auto; width: 400px; width: 370px; }
两⾏⼀列
CSS Code复制内容到剪贴板
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;}
三⾏⼀列
CSS Code复制内容到剪贴板
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; }
单⾏两列
CSS Code复制内容到剪贴板
#bodycenter { width: 700px;margin-right: auto; margin-left: auto;overflow: auto; }
#bodycenter #dv1 {float: left;width: 280px;}
#bodycenter #dv2 {float: rightright;width: 410px;}
两⾏两列
CSS Code复制内容到剪贴板
#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: rightright;width: 410px;}
三⾏两列
CSS Code复制内容到剪贴板
#header{ width: 700px;margin-right: auto; margin-left: auto; }
#bodycenter {width: 700px; margin-right: auto; margin-left: auto; }
#bodycenter #dv1 { float: left;width: 280px;}
html个人网页完整代码div+css#bodycenter #dv2 { float: rightright; width: 410px;}
#footer{ width: 700px; margin-right: auto; margin-left: auto; overflow: auto; }单⾏三列使⽤绝对定位
CSS Code复制内容到剪贴板
#left { position: absolute; top: 0px; left: 0px; width: 120px; }
sorted怎么用#middle {margin: 20px 190px 20px 190px; }
#right {position: absolute;top: 0px; rightright: 0px; width: 120px;}
float定位⼀
XML/HTML Code复制内容到剪贴板
<div id="warp">
<div id="column">
<div id="column1">这⾥是第⼀列</div>
<div id="column2">这⾥是第⼆列</div>
<div class="clear"></div>
</div>
<div id="column3">这⾥是第三列</div>
<div class="clear"></div>
</div>
CSS:
CSS Code复制内容到剪贴板
#wrap{ width:100%; height:auto;}
#column{ float:left; width:60%;}
#column1{ float:left; width:30%;}
mybaties插件#column2{ float:rightright; width:30%;}
#column3{ float:rightright; width:40%;}
.clear{ clear:both;}
float定位⼆:
XML/HTML Code复制内容到剪贴板
<div id="center" class="column">
<h1>This is the main content.</h1>
</div>
<div id="left" class="column">
<h2>This is the left sidebar.</h2>
</div>
<div id="right" class="column">
<h2>This is the right sidebar.</h2>
化学元素周期表口诀</div>
CSS:
CSS Code复制内容到剪贴板
body {margin: 0;padding-left: 200px;padding-right: 190px;min-width: 240px;} .column {position: relative;float: left;}
#center {width: 100%;}
#left {width: 180px; rightright: 240px;margin-left: -100%;}
#right {width: 130px;margin-right: -100%;}
两⾏三列:
XML/HTML Code复制内容到剪贴板
<div id="header">这⾥是顶⾏</div>
<div id="warp">
<div id="column">
<div id="column1">这⾥是第⼀列</div>
<div id="column2">这⾥是第⼆列</div>
<div class="clear"></div>
css
CSS Code复制内容到剪贴板
#header{width:100%; height:auto;}
#wrap{ width:100%; height:auto;}
#column{ float:left; width:60%;}
#column1{ float:left; width:30%;}
#column2{ float:rightright; width:30%;}
arm开发板
#column3{ float:rightright; width:40%;}
.clear{ clear:both;}
三⾏三列
XML/HTML Code复制内容到剪贴板
<div id="header">这⾥是顶⾏</div>
<div id="warp">
<div id="column">
<div id="column1">这⾥是第⼀列</div>
<div id="column2">这⾥是第⼆列</div>
<div class="clear"></div>
</div>
<div id="column3">这⾥是第三列</div> <div class="clear"></div>
</div>
<div id="footer">这⾥是底部⼀⾏</div> CSS:
CSS Code复制内容到剪贴板
#header{width:100%; height:auto;}
#wrap{ width:100%; height:auto;}
#column{ float:left; width:60%;}
#column1{ float:left; width:30%;}
#column2{ float:rightright; width:30%;} #column3{ float:rightright; width:40%;} .clear{ clear:both;}
#footer{width:100%; height:auto;}