百分比布局 双飞翼布局 圣杯布局

1.百分比布局:所有的百分比都是相对父级的

                   Div{ Width:50%;}div的宽是它父级元素的百分之五十

2.双飞翼布局 

             中间固定两边自适应

  <!DOCTYPE html>
  <html>
  <head>
    <meta charset="utf-8">
    <title>双飞翼布局</title>
    <style type="text/css">
      .left, .center, .right {
        float: left;
        min-height: 130px;
        text-align: center;
      }
      .left {
        margin-left: -100%;
        background: green;
        width: 200px;
      }

      .right {
        margin-left: -300px;
        background-color: red;
        width: 300px;
      }
      .center {
        background-color: blue;
        width: 100%;
      }
      .center1{
        margin: 0 300px 0 200px;
      }
    </style>
  </head>
  <body>
    <div class="cont">
      <div class="center">
        <div class="center1">center</div>
      </div>
      <div class="left">left</div>
      <div class="right">right</div>
    </div>
  </body>
  </html>

3.圣杯布局

         两端固定中间自适应

  

  <!DOCTYPE html>
  <html>
  <head>
    <meta charset="utf-8">
    <title>圣杯布局</title>
    <style type="text/css">
      .cont {
        padding: 0 300px 0 200px;
      }
      .left, .center, .right {
        position: relative;
        min-height: 130px;
        float: left;
      }
      .left {
        left: -200px;
        margin-left: -100%;
        background: green;
        width: 200px;
      }
      .right {
        right:-300px;
        margin-left: -300px;
        background-color: red;
        width: 300px;
      }
      .center {
        background-color: blue;
        width: 100%;
      }
    </style>
  </head>
  <body>
    <div class="cont">
      <div class="center">中间</div>
      <div class="left">左边</div>
      <div class="right">右边</div>
    </div>
  </body>
  </html>

 

Margin-right设置为整数 不会对自身元素造成影响 让平行元素往右移动

Margin-right设置为负数 自身元素就会向右移动

转载于:https://www.cnblogs.com/LXW2002326/p/11502593.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值