css什么是自适应布局,CSS自适应布局

今天小编介绍自适应布局实现方法的demo,

1)左侧固定宽度,右侧自适应,随着窗口的宽度而变化;

2)右侧固定宽度,左侧自适应;

3)中间自适应,两边定宽

1、左定宽

用左侧margin-left设为负宽度的方法,因为左侧脱离文档流,右侧宽度设为100%

效果如下:

acb0c922682c?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

left.png

代码如下:

.head{

display: block;

text-align: center;

line-height: 50px;

height: 40px;

background-color: yellow;

color: purple;

}

.body{

display: block;

height: 400px;

width: 100%;

}

.left{

float: left;

width: 100px;

height: 100%;

background-color: pink;

margin-right: -100px;

}

.right{

height: 100%;

width: 100%;

color: white;

background-color: lightblue;

float: left;

margin-left: 100px;

}

.foot{

display: block;

width: 100%;

height: 40px;

background-color: yellow;

text-align: center;

}

细节解释:line-height等于height可以使文本上下居中,如果line-height超过height,以height为准

2、右定宽

仍然采用margin方法,但这里有一个瑕疵,左侧的部分会被遮挡

acb0c922682c?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

right.png

.right{

float: right;

width: 100px;

height: 100%;

background-color: pink;

margin-left: -100px;

}

.left{

height: 100%;

width: 100%;

color: white;

background-color: lightblue;

float: left;

}

3、中间自适应

实现方法是,左右两边浮动,且在html中先写左右标签,后写中间标签,利用浏览器从上到下解析html标签的特点

acb0c922682c?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

middle.png

.body{

display: block;

height: 400px;

width: 100%;

}

.left{

height: 100%;

float: left;

width: 100px;

background-color: pink;

}

.middle{

background-color: lightblue;

height: 100%;

}

.right{

height: 100%;

float: right;

width: 100px;

background-color: lightgreen;

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值