双飞翼和圣杯

一、两种布局的目的

   使得左右两边的宽度是固定的,只有中间的部分自适应

二、双飞翼

 就是将元素嵌套到父级中,控制左右外边距(margin)进行调节

代码如下:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>css</title>
  </head>
  <style type="text/css">
    * {
      margin: 0;
      padding: 0;
    }
    .main > div {
      float: left;
      height: 200px;
    }
    .left {
      width: 200px;
      background: red;
      margin-left: -100%;
    }
    .right {
      width: 200px;
      background: blue;
      margin-left: -200px;
    }
    .middle {
      width: 100%;
      background: yellow;
    }
    .content {
      margin-left: 200px;
      margin-right: 200px;
    }
  </style>
  <body>
    <div class="main">
      <div class="middle">
        <div class="content">中间</div>
      </div>
      <div class="left">左边</div>
      <div class="right">右边</div>
    </div>
  </body>
</html>

效果图:

 

 

三、圣杯

就是将子元素嵌套到父级中,把子元素设置相对定位,控制子元素的左右内边距(padding)进行调节

代码如下:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>圣杯</title>
  </head>
  <style type="text/css">
    body {
      min-width: 550px;
    }
    * {
      margin: 0;
      padding: 0;
    }
    .main {
      height: 200px;
      padding: 0 150px 0 200px;
      background: greenyellow;
    }
    .left,
    .center,
    .right {
      float: left;
    }
    .center {
      width: 100%;
      height: 200px;
      background: red;
    }
    .left {
      width: 200px;
      height: 200px;
      background: yellow;
      margin-left: -100%;
      position: relative;
      left: -200px;
    }
    .right {
      width: 150px;
      height: 200px;
      background: skyblue;
      margin-left: -150px;
      position: relative;
      left: 150px;
    }
  </style>
  <body>
    <div class="main">
      <div class="center">中</div>
      <div class="left">左</div>
      <div class="right">右</div>
    </div>
  </body>
</html>

 效果图:

 好了,,就到这里了!!!!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值