CSS区分ie8和FF的方法?

html-css010

CSS区分ie8和FF的方法?,第1张

IE8现在还没有很好的解决兼容性的办法,但是IE8有一个方式是可以降低到IE7版本浏览。就是在每个以完成的页面源码中添加这句话:<meta http-equiv="X-UA-Compatible" content="IE=7" />这样,我们做好的成品页面即使在IE8中测试不兼容,加上上面那段代码,就可以把IE8的兼容性视图降低至IE7,一切就正常啦!以下是css兼容IE6、IE7和FF的方法:区分IE6,IE7,firefox

区别不同浏览器,CSS hack写法:

区别IE6与FF:

background:orange*background:blue

区别IE6与IE7:

background:green !importantbackground:blue

区别IE7与FF:

background:orange*background:green

区别FF,IE7,IE6:

background:orange*background:green_background:blue

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

注:IE都能识别*标准浏览器(如FF)不能识别*;

IE6能识别*,但不能识别 !important,

IE7能识别*,也能识别!important

FF不能识别*,但能识别!important

因为IE各版本的浏览器对我们制作的WEB标准的页面解释不一样,具体就是对CSS的解释不同,我们为了兼容这些,可运用条件注释来各自定义,最终达到兼容的目的

可使用如下代码检测当前IE浏览器的版本(注意:在非IE浏览器中是看不到效果的)

 /*判断浏览器的版本*/

<!––[if IE]> 

<h1>您正在使用IE浏览器</h1> <!––[if IE 5]> 

<h2>版本 5</h2> <![endif]––> 

<!––[if IE 5.0]> 

<h2>版本 5.0</h2> <![endif]––> 

<!––[if IE 5.5]> 

<h2>版本 5.5</h2> <![endif]––> 

<!––[if IE 6]> 

<h2>版本 6</h2> <![endif]––> 

<!––[if IE 7]> 

<h2>版本 7</h2> <![endif]––> 

<![endif]––>

那如果当前的浏览器是IE,但版本比IE5还低,该怎么办呢,可以使用<!–[if ls IE 5]>,当然,根据条件注释只能在IE5+的环境之下,所以<!–[if ls IE 5]>根本不会被执行。

 

< !–- 默认先调用css.css样式表 –-> 

<link rel="stylesheet" type="text/css" href="css.css" />< !-–[if IE 7]> 

<!–- 如果IE浏览器版是7,调用ie7.css样式表- –> 

<link rel="stylesheet" type="text/css" href="ie7.css" />< ![endif]–-> 

<!–-[if lte IE 6]> 

<!–- 如果IE浏览器版本小于等于6,调用ie.css样式表 -–> 

<link rel="stylesheet" type="text/css" href="ie.css" />< ![endif]–>

function isIE() { //ie?

if (!!window.ActiveXObject || "ActiveXObject" in window)

return true

else

return false

}

能判断是否为IE浏览器,但是控制版本型号 应该不行