三列布局中间自适应

方法1:
左边左浮动 右边又浮动 中间的写在html结构的最后加左右的margin

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
     body {
      margin: 0px;
      padding: 0px;
      overflow: hidden;
      min-width: 950px;
    }
    .left {
      width: 300px;
      background-color: red;
      float: left;
      height: 200px;
    }

    .right {
      width: 300px;
      background-color: blue;
      float: right;
      height: 200px;
    }

    .main {
      background-color: gray;
      margin: 0 300px;
      height: 200px;
    }
  </style>
</head>

<body>
  <div class="left">left</div>
  <div class="right">right</div>
  <div class="main">main</div>
</body>
</html> 

方法2:
与方法1类似 用定位代替margin

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    
    body {
      margin: 0px;
      padding: 0px;
      overflow: hidden;
      position: relative;
      min-width: 950px;
    }
    .left {
      width: 300px;
      height: 200px;
      background-color: red;
      float: left;
    }

    .right {
      width: 300px;
      background-color: blue;
      float: right;
      height: 200px;
    }

    .main {
      background-color: gray;
      position: absolute;
      left: 300px;
      right: 300px;
      height: 200px;
    }
  </style>
</head>
<body>
  <div class="left">left</div>
  <div class="main">main</div>
  <div class="right">right</div>
</body>
</html>

方法3: flex布局

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    .flex {
      display: flex;
    }

    .left,
    .right {
      width: 300px;
      height: 200px;
      background-color: red;
    }

    .right {
      background-color: blue;
    }
    .main {
      background-color: #ccc;
      flex: 1;
    }
  </style>
</head>

<body>
  <div class="flex">
    <div class="left"></div>
    <div class="main"></div>
    <div class="right"></div>
  </div>
</body>

</html> 

方法4:双飞翼布局

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
  body::after {
    display: block;
    content: '';
    clear: both;
  }
  .mainCounter {
    width: 100%;
    float: left;
    height: 200px;
  }
  .main {
    margin:0 300px;
    background-color: #ccc;
    height: 200px;
  }
  .left,.right{
    width: 300px;
    height: 200px;
    float: left;
    background-color: red;
    height: 200px;
  }
  .left {
    margin-left: -100%;
  }
  .right {
    background-color:blue;
    margin-left:-300px;
  }
  </style>
</head>
<body>
  <div class="mainCounter"><div class="main">中间</div></div>
  <div class="left">左边栏</div>
  <div class="right">右边栏</div>
</body>
</html> 

方法5:圣杯布局

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    .container {
      box-sizing: border-box;
      width: 100%;
      height: 200px;
      padding: 0 300px;
      min-width: 950px;
    }

    .main {
      width: 100%;
      float: left;
      height: 200px;
      background-color: #ccc;
    }

    .left,
    .right {
      float: left;
      width: 300px;
      height: 200px;
      background-color: red;
      position: relative;
    }

    .left {
      margin-left: -100%;
      left: -300px;
    }

    .right {
      margin-left: -300px;
      right: -300px;
    }
  </style>
</head>

<body>
  <div class="container">
    <div class="main">main</div>
    <div class="left">left</div>
    <div class="right">right</div>
  </div>
</body>

</html> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值