两栏以及三栏自适应布局

两栏以及三栏自适应布局

左边宽度200px, 右边自适应宽度

1. 左右都absolute,右right:0

左右两边都绝对定位,父元素相对定位

<div class="parent">
    <div class="left">
        <p>left</p>
    </div>
    <div class="right">
        <p>right</p>
        <p>right</p>
    </div>
</div>
.parent{
    position: relative;
}
.left{
  border: 1px solid red;
  position: absolute;
   
    width: 100px;
}
.right{
    position: absolute;
    border: 1px solid red;
    left: 120px;   
    right:0;

}

父元素 relative

左边列 absolute

右边 absolute, left: 100px, right:0  【实现自适应】

 

 

2. float:left + overflow:hidden

左边设置Margin 可把两列分开

<div class="parent">
    <div class="left">
        <p>left</p>
    </div>
    <div class="right">
        <p>right</p>
        <p>right</p>
    </div>
</div>
.left{
    float: left;
    width: 100px;
    margin-right: 20px;    
    border: 1px solid red;
}
.right{
    overflow: hidden; 
   border: 1px solid red;
}

 

3.  float + margin

.left {
    float: left;
    width: 200px;
    background-color: gray;
    height: 400px;
}
.right {
    margin-left: 210px;
    background-color: lightgray;
    height: 200px;
}

 

效果

image.png

三栏布局

1. 左边float:left, 中间Overflow:hidden; 右边 float:right

 <div class="container">
        <div class="left"></div>
        <div class="right"></div>
        <div class="main"></div>
    </div>
.left {
        float: left;
        height: 200px;
        width: 100px;
        margin-right: 20px;
        background-color: red;
    }
    .right {
        width: 200px;
        height: 200px;
        float: right;
        margin-left: 20px;
        background-color: blue;
    }   
    .main {
        height: 200px;
        overflow: hidden;
        background-color: green;
    }

 

 

2.  absolute + margin

<div class="box">
    <div class="left">左边</div>
    <div class="middle">中间</div>
    <div class="right">右边</div>
</div>

左右两边都设置绝对定位,中间的设置margin-left 和 margin-right

.box {
    position: relative;
}
.left {
    position: absolute;
    top: 0;
    left: 0;
    width: 200px;
    height: 200px;
    background-color: gray;
}
.right {
    position: absolute;
    top: 0;
    right: 0;
    width: 200px;
    height: 200px;
    background-color: gray;
}
.middle {
    margin-left: 210px;
    margin-right: 210px;
    background-color: lightgray;
    height: 200px;
}

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值