特色栏目

ASP源码

PHP源码

.NET源码

JSP源码

游戏频道
专题合集
关闭菜单
首页> 网页特效> 利用box-sizing实现div仿框架

利用box-sizing实现div仿框架

时间:2009-12-07 16:08:04 作者:互联网

[参与测试的浏览器:IE6 / IE7 / IE8 / FF3 / OP10 / SF4 / Chrome2 ]
[操作系统:Windows]

先看代码:

运行代码框
http://ww***.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://ww***.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://ww***.org/1999/xhtml">http://ww***.org/1999/xhtml">



http://ww***px.com">http://ww***px.com" title="Home" />
利用box-sizing实现div仿框架




 top


 side
 













 













 













 













 













 















 main
 













 













 













 













 













 















 bottom


[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

关键部分

html { -webkit-box-sizing:border-box; -moz-box-sizing:border-box; box-sizing:border-box; padding:100px 0; overflow:hidden;}

原理大概就是这样的

千言万语抵不过一副画,通过整容前后的对比,大家应该能看出box-sizing:border-box的作用了。

了解box-sizing的同学们应该知道,它来自离微国比较遥远的css3世界,因此IE6/IE7是不支持的,但我很负责任滴说:本demo正常兼容IE6/IE7。

因为……

IE6/IE7下,的box-sizing默认值本就是border-box(注:IE7有一点点不正常,overflow:hidden后神志有所恢复,将不影响本demo正常运作)。、

现在的问题就是是不是要采用这个方法了,给点优劣的对比,大家自行斟酌吧:

比较使用绝对定位的方法来实现,这个方法在目前主要存在两个优势:

  1. 针对每种浏览器基本使用的同一方法,css代码简单,易修改、易理解。
  2. 兼容。绝对定位的方法在OP10下存在暂时找不着修复bug的办法,只好绕个弯走了。

它最大的劣势就是欠灵活,如果没有IE6,我想我是坚决选择绝对定位的方法的。

以下为应用实例demo。

运行代码框
http://ww***.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://ww***.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://ww***.org/1999/xhtml">http://ww***.org/1999/xhtml">



http://ww***px.com">http://ww***px.com" title="Home" />
利用box-sizing实现div仿框架




 top


 side