单列变双列css_HTML CSS + DIV实现排版布局

HTML CSS + DIV实现排版布局

1.网页可以看成是由一个一个“盒子”组成,如图:

0a51fc4345bce851d3b85428801bd383.png

由上图可以看出,页面分为上(网站导航)、中、下(版权声明)三个部分,

中间部分又分为左(商品分类)、中(主要部分)、右,这些版块就像一个个

的盒子,这些"盒子"中放置着各种内容,页面就是由这些"盒子"拼凑起来

案例布局分析:

5728a849703a4a56527a08e4152dc5af.png

单列布局案例:

代码如下:

单列布局

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;

}

div{

text-align:center;

}

头部
主题

运行结果:

7294cba25abedbb60308f08fcd6c27a2.png

双列布局案例:

代码如下:

双列布局

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;

}

运行结果如下图:

dca6d0c5fbe847c9f184d8fa9edecbb9.png

三列布局案例:

代码如下:

三列布局

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;

}

运行结果如下图:

b13cb96e93339ef0e3d500c2f800c1d1.png

混合布局案例:

代码如下:

混合布局

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;

}

运行结果如下图:

9ee068820ea5ca6d551a76aede3023b5.png

总结:

排版布局需要掌握的知识

div 相关属性

float 浮动属性

position 定位属性

clear 清除浮动的应用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值