足球游戏_中国足彩网¥体育资讯$

css兼容性问题 && css hack
来源:易贤网 阅读:825 次 日期:2016-06-27 08:44:08
温馨提示:易贤网小编为您整理了“css兼容性问题 && css hack”,方便广大网友查阅!

以前做网页的时候,只考虑 ie6 和 ff 的兼容性,公司换了,要求也高了,ff和ie 6 7 8 要全兼容了,

碰到要单独hack ie8的。当然,用注释非常方便,只要添加相应的注释就可以解决。但问题是,为了一句css写多一个文件,或者在header上添加注释,那显然不是懒人的习惯做法。结论如下:

selector{

property:value; /* 所有浏览器 */

property:value9; /* 所有ie浏览器 */

+property:value; /* ie7 */

_property

当然,注意顺序。根据css的优先性,上面的写法,分别针对firefox、ie8、ie7和ie6显示值。让我们看看这个:

css代码如下:

代码如下:

p.ie{

height:60px;text-align:center;line-height:60px;border:1px dashed #bbb;background:#f7f7f7;font:15;

color:blue; // 所有浏览器

color:brown9; // 所有ie浏览器

+color:red; // ie7

_color:green; // ie6

}

html 代碼:

代码如下:

<body style=width:500px;margin:0 auto;>

<p class=ie>

<span style=display:block;display:none9;>嘿嘿,小子竟然也用firefox,蓝色文字。</span>

<!--[if ie 8]>不错不错,挺先进的嘛,使用ie8呢!文字是褐色的。<![endif]-->

<!--[if ie 7]>你,ie7,红色文字!<![endif]-->

<!--[if ie 6]>孩子,虽然显示的是绿色文字,不过,ie6可不是好东西呢!<![endif]-->

</p>

</body>

注意下面介绍的这些hack写法仅适用于xhtml1.0。如果没有在html最前加上

<!doctype html public -//w3c//dtd xhtml 1.0 transitional//en xmlns=>

那么效果将不一样!此外,这里所说的ie8,不是指ie8的兼容模式,因为ie8的兼容模式其实就是ie7。

区别ie6、7与ff/ie8:

background:blue;*background:orange;

引用

显示效果:

ie 6/7:orange

ff/ie8:blue

原理:ff/ie8不支持*开头,而ie6/7都支持。

区别ie6与ie7/ie8/ff:

background:green;_background:blue;

引用

显示效果:

ie7/8/ff:green

ie6:blue

原理:ie6支持下划线_,ie7、8和firefox均不支持下划线。

区别ff/ie8和ie6/7:

background:orange;+background:green;-background:blue;

或者

background:orange;*background:green!important;*background:blue;

引用

显示效果:

ie6:blue

ie7:green

ff/ie8:orange

原理:ie6能识别-,ie7能识别+,ie8和ff都不能识别+和-

ie8/ff都不识别*,ie7优先识别!important,ie6不能识别!important。

关于ie8的hacks:

.test{

color:/***/#00f9; /* ie8 only */

color:#00f9; /* 适用于所有ie版本 */

}

可同时区分ie8、ie7、ie6、firefox的css hacks:

.test{

color:#000; /* firefox */

color:/***/#00f9; /* ie8 */

*color:#f00; /* ie7 */

_color:#0f0; /* ie6 */

}

添加相应的注释解决兼容性问题

注释相应的css文件:

<link rel=stylesheet type=text/css href=css/style.css media=screen />

<!--[if ie 6]>

<link rel=stylesheet type=text/css href=css/ie6style.css media=screen />

<![endif]-->

<!--[if ie 7]>

<link rel=stylesheet type=text/css href=css/ie7style.css media=screen />

<![endif]-->

<!--[if gte ie 8]>

<link rel=stylesheet type=text/css href=css/ie8style.css media=screen />

<![endif]-->

注释相应的css 内容:

<!--[if ie 6]>

<style>

<!--

#warp{ padding-bottom:11px;}

-->

</style>

<![endif]-->

<!--[if ie 7]>

<style>

<!--

#warp{ padding-bottom:11px;}

-->

</style>

<![endif]-->

<!--[if ie 8]>

<style>

<!--

#warp{ padding-bottom:11px;}

-->

</style>

<![endif]-->

中国足彩网信息请查看网页制作
上一篇:css的链接美化
易贤网手机网站地址:css兼容性问题 &amp;&amp; css hack
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 足球游戏_中国足彩网¥体育资讯$ 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:易贤网
云南网警报警专用图标