识别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]-->

2021年恒创科技618活动:香港/美国服务器/云服务器/高防全场3折抢购

2021年恒创科技618活动香港美国服务器/云服务器/高防全场3折抢购,老客户续费送时长,每日限量秒杀。云服务器每款限量抢购,香港美国独服/高防每款限量5台/天,香港节点是CN2线路还不错。福利一:爆品秒杀 超低价秒杀,秒完即止;福利二:云服务器 火爆机型 3折疯抢;福利三:物理服务器 爆款直降 800元/月起;福利四:DDOS防护 超强防御仅 1750元/月。点击进入:2021年恒创科技618活...

香港ceranetworks(69元/月) 2核2G 50G硬盘 20M 50M 100M 不限流量

香港ceranetworks提速啦是成立于2012年的十分老牌的一个商家这次给大家评测的是 香港ceranetworks 8核16G 100M 这款产品 提速啦老板真的是豪气每次都给高配我测试 不像别的商家每次就给1核1G,废话不多说开始跑脚本。香港ceranetworks 2核2G 50G硬盘20M 69元/月30M 99元/月50M 219元/月100M 519元/月香港ceranetwork...

注册做什么96%可以干啥,常用的7个常用的国内国外域名注册服务商_云服务器可以干什么

日前,国内知名主机服务商阿里云与国外资深服务器面板Plesk强强联合,推出 阿里云域名注册与备案、服务器ECS购买与登录使用 前言云服务器(Elastic  只需要确定cpu内存与带宽基本上就可以了,对于新手用户来说,我们在购买阿里云服务申请服务器与域名许多云服务商的云服务器配置是弹性的 三周学会小程序第三讲:服务 不过这个国外服务器有点慢,可以考虑国内的ngrokcc。 ngrokcc...

csshack为你推荐
contentcss支持ipad设置media支持ipad支持ipad支持ipad联通版iphone4s苹果4s怎么分移动版联通版电信版?联通iphone4联通iphone4好用吗icloudiphone没开启icloud的iphone怎么用find my iphone找回csshack针对IE6的CSS HACK是什么?
海外主机 国外主机 hkbn mach5 sugarsync 美国主机论坛 商家促销 日本空间 gg广告 促正网秒杀 秒杀汇 可外链相册 vip购优惠 卡巴斯基破解版 免费私人服务器 闪讯官网 lamp架构 群英网络 登陆qq空间 开心online 更多