高度100%的绝对定位自适应布局

<script type="text/javascript"> </script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>

容器高度100%是经常用到的需求,任何容器都可以实现,而且不需要嵌套关系。

把body看作是一个容器,做为内部对象的上层标签,他的高度设置为100%是关键。

最基本的例子

* { margin:0; padding:0; border:0;}
html,body { height:100%;} /* 同时设置html是为了兼容FF */
#box_2 { height:100%; background:#000;}

效果演示:http://www.rexsong.com/blog/attachments/200512/23_133414_height100_base.htm

重叠绝对高度效果

#box_1 { position:absolute; top:0; left:0; width:100%; height:50px; background:#f00; z-index:2;}
#box_2 { position:absolute; left:0; top:0; width:100%; height:100%; background:#000; z-index:1;}

效果演示:http://www.rexsong.com/blog/attachments/200512/23_114301_height100_1.htm

纵向相对高度效果

#box_1 { position:absolute; top:0; left:0; width:100%; height:30%; background:#f00; z-index:2;}
#box_2 { position:absolute; left:0; top:30%; width:100%; height:70%; background:#000; z-index:1;}

效果演示:http://www.rexsong.com/blog/attachments/200512/23_115107_height100_2.htm

横向相对宽度效果

#box_1 { position:absolute; top:0; left:0; width:40%; height:100%; background:#f00; z-index:2;}
#box_2 { position:absolute; top:0; right:0; width:60%; height:100%; background:#000; z-index:1;}

这种布局是不需要float的,还可以有很多变化:

1,N列布局
2,N行布局
3,N列加N行交叉布局

值得注意的是在FF下浏览相对大小容器页面时,调整窗口大小的同时容器大小进行实时调整,而IE只会在窗口调整完毕后才出效果。

IE5.0 / IE5.5 / IE6.0和FF1.5测试通过

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值