圣杯布局与双飞翼布局

圣杯布局

    <div class="app">
        <div id="content">
            <!-- 中间内容优先渲染-->
            <div id="center" class="item">222</div>
            <div id="left" class="item">111</div>
            <div id="right" class="item">333</div>
        </div>
    </div>
    #content{
        padding:0 200px;
        .item {
            height:200px;
            float: left;
            position: relative;
          }
          #left{
            background-color: #f70303;
            width: 200px;
            margin-left: -100%;
            left: -200px;
          }
          #center{
            background-color: #04fd04;
            width: 100%;
          }
          #right{
            background-color: #3803fa;
            width: 200px;
            margin-left: -200px;
            right: -200px;
          }
    }

运行结果如下:

 

双飞翼布局

 <!-- 在圣杯基础的结构的基础上,中间容器里面嵌套了一个子容器,解决了圣杯用定位进行再次移动的问题
  双飞翼布局,没有定位进行位置的移动,简化了圣杯的代码(定位)
  -->
    <div id="parent">
      <div id="center">
        <div id="inner">inner</div>
      </div>
      <div id="left">left</div>
      <div id="right">right</div>
    </div>
    <!-- 双飞翼布局最早是淘宝团队提出,是针对圣杯布局的优化解决方案。
    主要是优化了圣杯布局中开启定位的问题。 -->
    * {
        margin: 0;
        padding: 0;
      }

      #parent {
        height: 500px;
      }

      #left,
      #center,
      #right {
        float: left;
      }

      #left,
      #right {
        width: 300px;
      }
      #left {
        background-color: #c9394a;
        margin-left: -100%;
      }

      #center {
        width: 100%;
        background-color: green;
      }

      #right {
        background-color: #cccccc;
        margin-left: -300px;
      }
      #inner {
        height: 300px;
        background-color: hotpink;
        margin-left: 300px;
        margin-right: 300px;
      }

运行结果如下:

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值