这篇文章主要介绍了关于HTML+CSS和DIV如何实现排版布局,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
HTML CSS + div实现排版布局
1.网页可以看成是由一个一个“盒子”组成,如图:
![1531469577206233.jpg 496770612-5b46ce6edc7b8_articlex[1].jpg](https://www.easck.com/d/file/p/2020/07-19/bb1d034b5216674701dba177229572e8.jpg)
由上图可以看出,页面分为上(网站导航)、中、下(版权声明)三个部分,
中间部分又分为左(商品分类)、中(主要部分)、右,这些版块就像一个个
的盒子,这些"盒子"中放置着各种内容,页面就是由这些"盒子"拼凑起来
案例布局分析:
![1531469585501570.jpg 1376923543-5b46cf378eab4_articlex[1].jpg](https://www.easck.com/d/file/p/2020/07-19/ecf9e988c524245e8bb374d844d0e43b.jpg)
单列布局案例:
代码如下:
<!doctype html><html> <head> <meta charset="utf-8"/> <title>单列布局</title> </head> <style> body{ margin:0; } .box{ width:960px; margin:0 auto; } .box .header{ height:120px; border:1px solid #f00; line-height:120px; } .box .main{ height:300px; border:1px solid #0f0; line-height:300px; } .box .footer{ height:100px; border:1px solid #00f; line-height:100px; } p{ text-align:center; } </style> <body> <p class="box"> <p class="header">头部</p> <p class="main">主题</p> <p class="footer">底部</p> </p> </body></html>运行结果:
![1531469598789189.png 4125081848-5b46d0aebc53f_articlex[1].png](https://www.easck.com/d/file/p/2020/07-19/2761c4956fb9985ca65cba6ef4820707.jpg)
双列布局案例:
代码如下:
<!doctype html><html> <head> <meta charset="utf-8"/> <title>双列布局</title> </head> <style> body{ margin:0; } .box{ width:80%; margin:0 auto; overflow:hidden; } .box .left{ width:30%; height:400px; background-color:#0f0; float:left; } .box .right{ width:70%; height:400px; background-color:#f00; float:left; } </style> <body> <p class="box"> <p class="left"></p> <p class="right"></p> </p> </body></html>运行结果如下图:
![1531469605477367.png 644704244-5b46d3b9c6eac_articlex[1].png](https://www.easck.com/d/file/p/2020/07-19/bb087f9f30899618eeab0d259e9eeb09.jpg)
三列布局案例:
代码如下:
<!doctype html><html> <head> <meta charset="utf-8"/> <title>三列布局</title> </head> <style> body{ margin:0; } .box{ width:960px; margin:0 auto; position:relative; } .box .left{ width:200px; height:400px; background-color:#0f0; position:absolute; } .box .center{ height:400px; background-color:#00f; margin:0 300px 0 200px; } .box .right{ width:300px; height:400px; background-color:#f00; position:absolute; right:0; top:0; } </style> <body> <p class="box"> <p class="left"></p> <p class="center"></p> <p class="right"></p> </p> </body></html>运行结果如下图:
![1531469612465577.png 301091421-5b46d50ad43e5_articlex[1].png](https://www.easck.com/d/file/p/2020/07-19/9b420bde9e407419aef8a7ce9422e8c1.jpg)
混合布局案例:
代码如下:
<!doctype html><html> <head> <meta charset="utf-8"/> <title>混合布局</title> </head> <style> body{ margin:0; } .box{ width:960px; margin:0 auto; } .header{ height:120px; background-color:#ddd; } .main{ height:400px; background-color:#f00; position:relative; } .main .left{ width:200px; height:400px; position:absolute; left:0; top:0; background-color:#0fccaa; } .main .center{ height:400px; margin:0 305px 0 205px; background-color:#123456; } .main .right{ width:300px; height:400px; position:absolute; right:0; top:0; background-color:#ff0; } .footer{ height:80px; background-color:#ddd; } </style> <body> <p class="box"> <p class="header"></p> <p class="main"> <p class="left"></p> <p class="center"></p> <p class="right"></p> </p> <p class="footer"></p> </p> </body></html>运行结果如下图:
![1531469627745767.png 2619066118-5b46d5e7b3d8f_articlex[1].png](https://www.easck.com/d/file/p/2020/07-19/62d07c6a93cb804116355ca4ea480c65.jpg)









