自适应布局 左右结构、上下结构

一、左右结构   左边固定,右边自适应

1. 左边左浮动,右边加个overflow:hidden;

   #lt{ float: left;width:200px; background: #ff0;}

   #rt{ overflow: hidden; background: #f0f;}

2. 左边左浮动,右边加个margin-left;

   #lt{ float: left; width:200px; background: #ff0;}

   #rt{ margin-left: 200px; background: #f0f;}

3. 左边绝对定位,右边加个margin-left;

   #lt{ position: absolute; top:0; left:0; width:200px; background: #ff0;}

   #rt{ margin-left: 200px; background: #f0f;}

4. 左右两边绝对定位,右边加个width,top,left,right

 #lt{ position: absolute; top:0 ; left:0 ;width:200px; background: #ff0;}

 #rt{ position: absolute; top:0 ; left:200px; width: 100% ; rigth:0;background: #f0f;}

二、左右结构 右边固定,左边自适应的布局

1. 左边左浮动,margin-left负值,右边右浮动;

#lt{float:left; width:100%;background: #00f;margin-right: -200px;}
#rt{float: right; width: 200px;background: #ff0;}

2. 右边绝对定位,左边margin-right;

   #lt{margin-right:200px; background: #00f;}

   #rt{ position: absolute; right:0; top:0; width: 200px;background: #ff0;}

3. 左右两边绝对定位,左边加个width,top,left,right

   #lt{ position: absolute; top:0; left:0; rigth:0; width: 100% ; background: #f0f;}

   #rt{ position: absolute; top:0; left:200px; width:200px; background: #ff0;}

三、上下结构自适应

 .header,.footer{
      width: 100%;
      height: 100px;
      line-height: 100px;
      background-color: red;
 }
.content{
       width: 100%;
        position: absolute;
         top: 100px;
         bottom:100px;
          background-color: yellow;
}
.footer{
    position: absolute;
    bottom: 0px;
}

    <div class="header">头部</div>
    <div class="content">内容</div>
    <div class="footer">底部</div>            

 

转载于:https://www.cnblogs.com/SPHmomo/p/7531392.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值