两栏布局和三栏布局

两列布局:左固定、右适应

<body>
   <div class="box">
     <div class="aside"></div>
     <div class="main"></div>
   </div>
</body>
  1. float + BFC
.aside{
 float: left;
   width: 200px;
   height: 200px;
   background-color: aqua;
 }
 .main{
   background-color: aquamarine;
   height: 200px;
   overflow: auto;
 } 
  1. float + margin-left
.aside{
 float: left;
  width: 200px;
  height: 200px;
  background-color: aqua;
}
.main{
  background-color: aquamarine;
  height: 200px;
  margin-left: 200px;
}
  1. flex
.box{
 display: flex;
 }
 .aside{
   width: 200px;
   height: 200px;
   background-color: aqua;
 }
 .main{
   background-color: aquamarine;
   flex: 1;
   height: 200px;
 }

三栏布局

  1. float + BFC
</style>
.left,.main,.right {
      height: 200px;
    }
    .left {
      float: left;
      width: 200px;
      background-color: red;
    }
    .main{
      overflow: hidden;
      background-color: hotpink;
    }
    .right{
      float: right;
      width: 200px;
      background-color: green;
    }
  </style>
</head>
<body>
   <div class="box">
     <div class="left"></div>
     <div class="right"></div>
     <div class="main"></div>
   </div>
</body>
  1. flex
 .box{
      display: flex;
    }
    .left,.right,.main{
        height: 200px;
    }
    .left , .right {
      width: 200px;
      background-color: hotpink;
    }
    .main{
      background-color: red;
      flex: 1;
    }
  </style>
</head>
<body>
   <div class="box">
     <div class="left"></div>
     <div class="main"></div>
     <div class="right"></div>
   </div>
</body>
  1. 圣杯
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>三栏布局——圣杯布局</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    body {
      min-width: 550px;
    }
    .container {
      padding: 0 150px 0 200px;
      overflow: hidden;
    }
    .column {
      position: relative;
      float: left;
      min-height: 100px;
    }
    .left {
      left: -200px;
      margin-left: -100%;
      width: 200px;
      background: #ffbbff;
    }
    .center {
      width: 100%;
      background: #bfefff;
    }
    .right {
      right:-150px;
      margin-left: -150px;
      width: 150px;
      background: #eeee00;
    }
  </style>
</head>
<body>
  <div class="container">
    <div class="column center">center</div>
    <div class="column left">left</div>
    <div class="column right">right</div>
  </div>
</body>
</html>
  1. 双飞翼
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>三栏布局——双飞翼布局</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    body {
      min-width: 550px;
    }
    .container {
      overflow: hidden;
    }
    .column {
      float: left;
      min-height: 100px;
    }
    .left {
      margin-left: -100%;
      width: 200px;
      background: #ffbbff;
    }
    .center {
      width: 100%;
    }
    .center-inner {
      margin: 0 150px 0 200px;
      min-height: 100px;
      background: #bfefff;
    }
    .right {
      margin-left: -150px;
      width: 150px;
      background: #eeee00;
    }
  </style>
</head>
<body>
  <div class="container">
    <div class="column center">
      <div class="center-inner">center</div>
    </div>
    <div class="column left">left</div>
    <div class="column right">right</div>
  </div>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值