继续上一篇,当时那个布局是采用浮动的方式来制作的,但是有个缺点就是高度不能够自适应,后来 aoao 在留言里提示是这样说的:
如果你先把它理解成两栏,然后使用负值偏移,就可以做到这样的布局。
因为是两栏浮动,对于高度自适应,就简单多了。
是的,接下来的这个布局结构就是按照aoao的方法来做~
先分成两列,然后利用负边值来搞定那个最难的问题,
结构代码:
- <div id="main">
- <div class="header"></div>
- <div class="left-part">
- <div class="left-1">1</div>
- <div class="right-1">2</div>
- <div class="right-2">3</div>
- <div class="mid-1">5</div>
- <div class="left-2">6</div>
- <div class="right-3">7</div>
- <div class="clear"></div>
- </div>
- <div class="right-part">
- <div class="right-part-1">4</div>
- </div>
- <div class="footer"></div>
- </div>
CSS样式:
- #main { margin: 30px auto; width: 760px;}
- .header { margin-bottom: 10px; width: 760px; height: 28px; border: 1px #6c6c6c solid; background: #292928;}
- .left-part { float: left; width: 490px; margin-bottom: 10px;}
- .left-1 { float: left; width: 180px; height: 300px; border: 1px #6c6c6c solid; background: #292928; margin-bottom: 10px;}
- .right-1 { float: right; width: 570px; border: 1px #6c6c6c solid; background: #292928; height: 100px; position: relative; z-index: 1000; margin-right: -272px;}
- .right-2 { float: right; margin: 10px -2px 10px 0; width: 300px; height: 188px; border: 1px #6c6c6c solid; background: #292928; position: relative; z-index: 1000;}
- .mid-1 { clear: both; width: 490px; height: 60px; border: 1px #6c6c6c solid; background: #292928; margin-bottom: 10px;}
- .left-2 { float: left; width: 180px; height: 148px; border: 1px #6c6c6c solid; background: #292928;}
- .right-3 { float: right; width: 300px; height: 148px; border: 1px #6c6c6c solid; background: #292928; margin-right: -2px; position: relative; z-index: 1000;}
- .right-part { float: right; width: 260px; padding-top: 112px; margin-bottom: 10px;}
- .right-part-1 { width: 100%; height: 420px; border: 1px #6c6c6c solid; background: #292928; margin-right: -2px; position: relative; z-index: 1000;}
- .footer { clear: both; width: 760px; height: 28px; border: 1px #6c6c6c solid; background: #292928; margin-bottom: 30px;}
Demo 地址:http://blog.ikshow.cn/demo/layout_position_2/
这样的一个结构就能实现高度自适应了,但是回过头想一下,这种布局有必要高度自适应吗?如果是宽度自适应的话那更加的难,现实中使用应该还是定好了高度,就像第一个方法一样!不过这样做也添加了多几个乐趣~呵呵!xhtml+css真的太好玩了!

1楼的 aoao 说:
高度自适应是一种无聊的练习。
真的想练技术就练弹性布局吧。那才好玩。。
[06月 1st, 2007 at 12:58 pm]
2楼的 iVane 说:
嘿嘿!以前有个项目是需要到弹性布局的,那次做一个页面是需要好多时间的,T_T
[06月 1st, 2007 at 6:36 pm]