FF、IE7、IE6的CSS hack写法

一套皮肤对于定位有着严格的要求,歪一点点都不行,所以不得不用到一些CSS Hack来解决。针对不同的浏览器写不同的CSS code的过程,就叫CSS hack,也叫写CSS hack。

1、!important
IE7和FF下都支持!important 的,可以用!important来区分FF、IE7和IE6的高度。
.content{background:#f00;height:100px !important;}/* FF+IE7 */  
.content{background:#f00;height:200px;}/* IE6 */


2、IE6/IE7对FireFox
 *+html 与 *html 是IE特有的标签, firefox 暂不支持。
而*+html 又为 IE7特有标签,IE6暂不支持。
.content{background:#f00;height:100px;}/* FF */  
*html .content{background:#f00;height:200px;}/* IE6 */  
*+html .content{background:#f00;height:300px;}/* IE7 */

height:50px; /*FF*/  
*height:100px; /*For IE7 & IE6*/  
_height:150px; /*For IE6*/  

可以用相同的原理来为IE6、IE7、FF设置不同的width,height,margin,padding等属性。

3、区别不同浏览器,Css hack写法:
区别IE6与FF:
background:orange;       *background:blue;

区别IE6与IE7:
background:green !important;     background:blue;

区别IE7与FF:
background:orange;      *background:green;

区别FF,IE7,IE6:
background:orange;    *background:green !important;    *background:blue;

还有就是使用时的排序问题,我认为:不管是什么方法,书写的顺序都是firefox的写在前面,IE7的写在中间,IE6的写在最后面。

附:CSS的各种浏览器兼容一栏表:


[本日志由 蛛蛛虎 于 2010-01-03 11:58 PM 编辑]
上一篇: 加速IE8打开速度
下一篇: U盘安装Windows7
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: css
相关日志:
评论: 0 | 引用: 0 | 查看次数: -
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 支持Gravatar头像.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.