合肥市高新區(qū)長(zhǎng)江西路與科學(xué)大道交口5F創(chuàng)業(yè)園A座309
136 5560 1775

CSS兼容性 CSS區(qū)分IE6 IE7 IE8 firefox

發(fā)表日期:2010-03-10 瀏覽次數(shù):3194次

合肥啟邁匯總CSS區(qū)分IE6 IE7 IE8 firefox(安徽網(wǎng)站建設(shè))

selector{
property:value; /* 所有瀏覽器 */
property:value9; /* 所有IE瀏覽器 */
+property:value; /* IE7 */
_property
當(dāng)然,注意順序。根據(jù)CSS的優(yōu)先性,上面的寫法,分別針對(duì)Firefox、IE8、IE7和IE6顯示值。讓我們看看這個(gè):

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,藍(lán)色文字。</span>
<!--[if IE 8]>不錯(cuò)不錯(cuò),挺先進(jìn)的嘛,使用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"><html xmlns="http://www.w3.org/1999/xhtml">

那么效果將不一樣!此外,這里所說的IE8,不是指IE8的兼容模式,因?yàn)镮E8的兼容模式其實(shí)就是IE7。


區(qū)別IE6、7與FF/IE8:
       background:blue;*background:orange;

引用
顯示效果:
IE 6/7:orange
FF/IE8:blue
原理:FF/IE8不支持*開頭,而IE6/7都支持。


區(qū)別IE6與IE7/IE8/FF:
       background:green;_background:blue;

引用
顯示效果:
IE7/8/FF:green
IE6:blue
原理:IE6支持下劃線"_",IE7、8和firefox均不支持下劃線。

 

區(qū)別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能識(shí)別-,IE7能識(shí)別+,IE8和FF都不能識(shí)別+和-
IE8/FF都不識(shí)別*,IE7優(yōu)先識(shí)別!important,IE6不能識(shí)別!important。


關(guān)于IE8的hacks:

.test{
     color:/***/#00f9; /* IE8 only */

     color:#00f9; /* 適用于所有IE版本 */
}


可同時(shí)區(qū)分IE8、IE7、IE6、Firefox的CSS hacks:
.test{
     color:#000; /* Firefox */
     color:/***/#00f9; /* IE8 */
     *color:#f00; /* IE7 */
     _color:#0f0; /* IE6 */
}

 


添加相應(yīng)的注釋解決兼容性問題

注釋相應(yīng)的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]-->

 

注釋相應(yīng)的Css 內(nèi)容:

<!--[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]-->

 

安徽網(wǎng)站建設(shè)


將文章分享到:

版權(quán)所有:?jiǎn)⑦~科技-合肥網(wǎng)站建設(shè) 皖I(lǐng)CP備19009304號(hào)-1 皖公網(wǎng)安備 34010402702162號(hào)

網(wǎng)站建設(shè),網(wǎng)站設(shè)計(jì)公司啟邁科技,為眾多企業(yè)提供網(wǎng)站建設(shè),網(wǎng)站制作,響應(yīng)式網(wǎng)站設(shè)計(jì),手機(jī)網(wǎng)站建設(shè),微網(wǎng)站,模板建站,企業(yè)郵箱等一站式互聯(lián)網(wǎng)解決方案和建站服務(wù)10年。