三栏布局和两栏布局

1.三栏布局

在这里插入图片描述是多少
左右固定,中间自适应

1.浮动布局

.main {
    height: 300px;
    margin:0 300px;
    background: green;
}
.left {
    float: left;
    height: 300px;
    width: 200px;
    background: red;
}
.right {
    float: right;
    width: 200px;
    height: 300px;
    background: blue;
}
<div class="container">
     <div class="left"></div>
     <div class="right"></div>
     <div class="main"></div>  
</div>

2.定位布局

.container {
    position: relative;
}
.left {
    position: absolute;
    width: 200px;
    height: 300px;
    left: 0;
    background: red;
}
.right {
    position: absolute;
    width: 200px;
    height: 300px;
    background: blue;
    right: 0
}
.main {
    height: 300px;
    background: green;
    margin:0 300px;
}
<div class="container">
     <div class="left"></div>
     <div class="right"></div>
     <div class="main"></div>
</div>

3.flex布局

.container {
    display: flex;
}
.main {
    flex:1;
    background:green;
    margin:0 100px;
}
.left {
    width: 200px;
    height: 300px;
    background: red;
}
.right {
    width: 200px;
    height: 300px;
    background: blue;
} 
<div class="container">
     <div class="left"></div>
     <div class="main"></div>
     <div class="right"></div>  
</div>

2.两栏布局

在这里插入图片描述
左边固定,右边自适应

1.浮动布局

.left {
    width: 200px;
    height: 300px;
    float: left;
    background: red;
}
.right {
    background: blue;
    margin-left: 300px;
    height: 300px;
}

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

2.定位布局

.container {
    position: relative;
}
.left {
    position:absolute;
    width: 200px;
    height: 300px;
    left:0;
    background: red;
}
.right {
    background: blue;
    margin-left:300px;
    height: 300px;
} 
 <div class="container">
      <div class="left"></div>
      <div class="right"></div>
 </div>

3.flex布局

.container{
    display:flex;
}
.left{
    width: 200px;
    height: 300px;
    background: red;
}
.right{
    flex:1;
    height: 300px;
    background:blue;
    margin-left:100px;
} 
 <div class="container">
      <div class="left"></div>
      <div class="right"></div>
 </div>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值