识别Css兼容性问题CSShack区分IE6IE7IE8firefox

csshack  时间:2021-04-22  阅读:()

selector{property:value; /*所有浏览器*/property:value\9; /*所有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:brown\9; //所有IE浏览器

+color:red; // IE7

_color:green; // IE6

}

HTML代碼

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

<p class="ie">

<span style="display:block;display:none\9;">嘿嘿小子竟然也用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"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml">

那么效果将不一样此外这里所说的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:/*\**/#00f\9; /* IE8 only */color:#00f\9; /*适用于所有IE版本*/

}

可同时区分IE8、 IE7、 IE6、 Firefox的CSS hacks

. test{color:#000; /* Firefox */color:/*\**/#00f\9; /* 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]-->

美得云(15元/月)美国cera 2核4G 15元/月 香港1核 1G 3M独享

美得云怎么样?美得云好不好?美得云是第一次来推广软文,老板人脾气特别好,能感觉出来会用心对待用户。美得云这次为大家提供了几款性价比十分高的产品,美国cera 2核4G 15元/月 香港1核 1G 3M独享 15元/月,并且还提供了免费空间给大家使用。嘻嘻 我也打算去白嫖一个空间了。新用户注册福利-8折优惠码:H2dmBKbF 截止2021.10.1结束。KVM架构,99.99%高可用性,依托BGP...

ThomasHost(月付5美元)美国/法国/英国/加拿大KVM,支持Windows

ThomasHost域名注册自2012年,部落最早分享始于2016年,还算成立了有几年了,商家提供基于KVM架构的VPS,数据中心包括美国、法国、英国、加拿大和爱尔兰等6个地区机房,VPS主机套餐最低2GB内存起步,支持Windows或者Linux操作系统,1Gbps端口不限制流量。最近商家提供了一个5折优惠码,优惠后最低套餐月付5美元起。下面列出部分套餐配置信息。CPU:1core内存:2GB硬...

iHostART:罗马尼亚VPS/无视DMCA抗投诉vps;2核4G/40GB SSD/100M端口月流量2TB,€20/年

ihostart怎么样?ihostart是一家国外新商家,主要提供cPanel主机、KVM VPS、大硬盘存储VPS和独立服务器,数据中心位于罗马尼亚,官方明确说明无视DMCA,对版权内容较为宽松。有需要的可以关注一下。目前,iHostART给出了罗马尼亚vps的优惠信息,罗马尼亚VPS无视DMCA、抗投诉vps/2核4G内存/40GB SSD/100M端口月流量2TB,€20/年。点击直达:ih...

csshack为你推荐
"2018年中文图书第5期新书通报",,,,,http://www.huajinsc.cn/namesgraph输入ipad支持ipadtracerouteLinux 下traceroute的工作原理是什么 !iphone连不上wifi我的苹果手机连不上无线,其它手机能,怎么回事?只是家里的连不上iphone连不上wifi苹果iphone6/plus wifi连接不上怎么办win10445端口windows server2008怎么开放4443端口tcpip上的netbios网络连接详细信息上的netbios over tcpip是什么意思?
php主机租用 如何查询ip地址 virpus lunarpages cpanel主机 美国主机论坛 轻博 typecho 免费ftp空间申请 godaddy域名证书 如何用qq邮箱发邮件 腾讯总部在哪 免费ftp 日本代理ip 万网空间 摩尔庄园注册 万网注册 阿里云邮箱怎么注册 谷歌搜索打不开 wordpress空间 更多