多列布局之定宽+自适应

多列布局之定宽+自适应

说明
本文所述仅为主要样式
具体样式和HTML文件,请点击https://github.com/smilehht/Page-Framework/tree/master/Page%20framework/%E5%A4%9A%E5%88%97%E5%B8%83%E5%B1%80/1.%E5%AE%9A%E5%AE%BD%E5%8A%A0%E8%87%AA%E9%80%82%E5%BA%94

1、float+margin——单侧浮动

.left { float:left; width : 200px; }
.right{ margin-left : 220px; }

优点:
兼容性好
缺点:
.right清除浮动会产生bug(右侧会掉下去)

2、float+margin——双侧浮动

.left { float:left; width : 200px ; position : relative ; }
.right-parent{ float:right; width:100%;margin-left:-200px; }
.right-child{ margin-left : 220px; }

position:relative;——提高left的层级,因为right-parent也会浮动,会覆盖left与right部分无法显示在同一个高度上

优点:
兼容性好
缺点:
样式较多

3、flow+overflow

.left { float : left ; width:200px; margin-right : 20px ; }
.right { overflow : hidden ; }

overflow:hidden——触发BFC模式内部与外部隔离(如浮动元素不会影响BFC中的内容)

优点:
代码简单
缺点:
IE6不支持

4、table布局

.parent{ display : table ; width : 100% ; table-layout : fixed ; }
.left , .right { display : table-cell ; }
.left { width : 200px ; padding-right : 20px ; }

width:100%——table默认宽度随内容而定
table-layout:fixed——加速table的渲染,且实现了布局优先
display:table-cell——实现了单元格在同一行排列

5、flex布局

.parent { display:flex; }
.left { width:100px;margin-left:20px; }
.right { flex:1; }

缺点:
兼容性不好
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值