圣杯布局&双飞翼布局

圣杯布局有个问题,当面板的center部分比两边的子面板宽度小的时候,布局就会乱掉。

因此也就有了双飞翼布局来克服这个问题。双飞翼布局在center上添加一个标签。

要了解这两个布局 看再多不如自己写几遍 很多东西网上不会讲解很细 但是自己实现几遍 会豁然开朗


圣杯布局 

center面板先占满整行 两边面板被挤下去 然后center用padding来留出空白给两边面板 

两边面板 left面板用margin负值 -100%就是向左移动整个center的宽度(是不包括两边留白的padding),

right面板 -250px 向左移动自身宽度的大小 才能够恰好挤进上一行

最后用相对定位把两边面板移到该在的位置。

css:

.main { padding: 0 250px 0 300px;overflow: hidden;}
.center { width: 100%; height: 600px; background: grey; float: left;}
.left { width: 300px; height: 600px; background: yellow; float: left; margin-left: -100%; position: relative; left: -300px;}
.right { width: 250px; height: 600px; background: green; float: left; margin-left: -250px; position:relative; right: -250px;}

html:

<div class="main">
        <div class="center"></div>
        <div class="left"></div>
        <div class="right"></div>
</div>



双飞翼布局

center面板先占满整行 两边面板被挤下去 

在center中还有一层div,centerin用来设置左右margin给两边面板留位置,

两边面板 left面板用margin负值 -100% 向左移动整个center的宽度 ,right面板-250px移动整个自身的宽度

css:

.main { overflow: hidden;}
.center { width: 100%; height: 600px; background: grey; float: left;}
.centerin { margin: 0 250px 0 300px;}
.left { width: 300px; height: 600px; background: yellow; float: left;margin-left: -100%;}
.right { width: 250px; height: 600px; background: green; float: left;margin-left: -250px;}

html:

<div class="main">
    <div class="centerBig">
        <div class="center"></div>
    </div>
    <div class="left"></div>
    <div class="right"></div>
</div>



左边是圣杯 右边是双飞翼


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值