区别IE6与FF:
       background:orange;
       *background:blue;

区别IE6与IE7:
       background:green !important;
       background:blue;

区别IE7与FF:
       background:orange;
       *background:green;
       
方法一:在同一个CSS样式表中,使用 !important 来定义不同的值以适应Firefox和IE,例如:

padding: 20px !important;  /*For Firefox*/
padding: 10px;              /*For IE*/
(注意这里IE6是无法识别 !important 这个标记的,但它会识别padding: 20px,所以要在后面加上padding: 10px用来覆盖padding: 20px)

这个方法适用于修改少量代码。

例一:

CSS
#box {
     color:red !important;
     color:blue;
 }

HTML
<div id="Box"> 在不同的浏览器下,这行字的色应该不同!</div>

这个例子在IE6环境下,这行字是蓝色,在IE7及firefox下,为红色。
这是因为IE6不认important(即不认 !importmant 但是还是认!important前面的color:red),并且color:blue放
在color:red的后面(后面的css定义覆盖了前面的color:red),所以在IE6下字为蓝色;而在IE7及firefox下
important级别优先,所以color:red !important;和color:blue;的前后顺序没有关系,在IE7及firefox下red跟
blue谁先谁后都没有关系。

方法二:条件注释 (只对IE浏览器有效)先为不同浏览器书写各自的CSS样式,再在head中加入以下的代码以适应不同的IE浏览器版本调用:

<!--[if IE]>
According to the conditional comment this is Internet Explorer<br />
<![endif]-->

<!--[if IE 5]>
According to the conditional comment this is Internet Explorer 5<br />
<![endif]-->

<!--[if IE 5.0]>
According to the conditional comment this is Internet Explorer 5.0<br />
<![endif]-->

<!--[if IE 5.5]>
According to the conditional comment this is Internet Explorer 5.5<br />
<![endif]-->

<!--[if IE 6]>
According to the conditional comment this is Internet Explorer 6<br />
<![endif]-->

<!--[if IE 7]>
According to the conditional comment this is Internet Explorer 7<br />
<![endif]-->

<!--[if gte IE 5]>
According to the conditional comment this is Internet Explorer 5 and up<br />
<![endif]-->

<!--[if lt IE 6]>
According to the conditional comment this is Internet Explorer lower than 6<br />
<![endif]-->

<!--[if lte IE 5.5]>
According to the conditional comment this is Internet Explorer lower or equal to 5.5<br />
<![endif]-->

<!--[if gt IE 6]>
According to the conditional comment this is Internet Explorer greater than 6<br />
<![endif]-->

<!–[if !IE 6.0]>此内容除了IE6.0版本之外都可见<![endif]–>

另外:IE还支持一个非标准的标签:comment
<p>This is <comment>not</comment> Internet Explorer.</p>
This is Internet Explorer.

IE会自动把此标签中的内容当作注释处理掉。

方法三:javascript. 判断不同的浏览器类型以调用不用的css

//后面为注释

<SCRIPT. LANGUAGE="JavaScript">
<!--
if (window.navigator.userAgent.indexOf("MSIE")>=1)
...{
//如果浏览器为IE
setActiveStyleSheet("ie.css");
}else...{
if (window.navigator.userAgent.indexOf("Firefox")>=1)
...{
//如果浏览器为Firefox
setActiveStyleSheet("ff.css");
}else...{
//如果浏览器为其他
setActiveStyleSheet("an.css");
}
}

function setActiveStyleSheet(title)...{
document.getElementsByTagName("link")[0].href="/blog/css/"+title;
}
//-->
</SCRIPT>

javascrip判断的第二种方法

<script. language=javascript>
<!--
if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4))
{
document.write('<link rel=stylesheet type="text/css" href="ie.css">')
}
else {document.write('<link rel=stylesheet type="text/css" href="ns.css">')}
//-->
</script>

方法四:在css里为特定浏览器设置

height:20px; /*For all 包括火狐 */
*height:25px; /*For IE7 & IE6*/
_height:20px; /*For IE6*/
*+height:20px /* IE7 */

在css里面就是那么几句会让不同的浏览器显示的不一样.我们只要把不兼容的那句设定给特定的浏览器,也可以实现完美兼容了

"/9" 例:"margin:0px auto/9;".这里的"/9"可以区别所有IE和FireFox.
"*" IE6、IE7可以识别.IE8、FireFox不能.
"_" IE6可以识别"_",IE7、IE8、FireFox不能.
*+ 针对IE7

在不同的浏览器使用不同的css样式,解决浏览器兼容问题的更多相关文章

  1. 如何让不同浏览器调用不同的CSS样式

    如何让不同浏览器调用不同的CSS样式 由 于对W3C标准支持程度的不同,往往导致同一个CSS样式表在各种Web浏览器中的呈现大相径庭.以目前市场占有率最高的两个浏览器Microsoft Interne ...

  2. CSS样式 解决文字过长显示省略号问题

    一.CSS样式 解决文字过长显示省略号问题 1.一般样式 一般 css 样式,当宽度不够时,可能会出现换行的效果.这样的效果在某些时候肯定是不行的,可以修改 css 样式来解决这个问题. <!D ...

  3. CSS Hack解决浏览器IE部分属性兼容性问题

    1.Css Hack 不同厂商的流览器或某浏览器的不同版本(如IE6-IE11,Firefox/Safari/Opera/Chrome等),对CSS的支持.解析不一样,导致在不同浏览器的环境中呈现出不 ...

  4. 如何根据不同的浏览器写不同的css样式达到兼容

    做前端静态页面的时候总是发现,ie的兼容性很差,总会出点问题.然后就去改代码 ,改完以后 又发现 火狐 谷歌又挂了,这可咋整.     后来发现做个判断吧 哪里有问题哪里就做个判断呗 ,咋判断呢,这么 ...

  5. 怎样使一个宽为200px和高为200px的层垂直居中于浏览器中?写出CSS样式代码。

    div{ height:100px; width:100px; position:absolute; top:50%; width:50%; margin-letf:-100px; margin-to ...

  6. js的append拼接html丢失css样式解决

    htmlApp += "<li id='leftli"+lunci+"'>"; htmlApp += "<span id='left ...

  7. CSS样式总结

    CSS: Cascading Style Sheet,层叠样式表 Css由三部分组成:选择符.样式属性.值: 基本语法:选择符 {样式属性:值:样式属性:值.....} 一,选择器 常用的选择器有:标 ...

  8. 前端之css样式(选择器)。。。

    一.css概述 CSS是Cascading Style Sheets的简称,中文称为层叠样式表,对html标签的渲染和布局 CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明. 例如 二.c ...

  9. 初始化 CSS 样式

    为什么要初始化 CSS 样式 因为浏览器的兼容问题,不同浏览器对有些标签的默认值是不同的,如果没对 CSS 初始化往往会出现浏览器之间的页面显示差异. 当然,初始化样式会对 SEO 有一定的影响,但鱼 ...

随机推荐

  1. 用MongoDB取代RabbitMQ(转)

    原文:http://blog.nosqlfan.com/html/3223.html RabbitMQ是当成应用比较广泛的队列服务系统,其配套的客户端和监控运维方案也比较成熟.BoxedIce的队列服 ...

  2. SQL基础--查询之四--集合查询

    SQL基础--查询之四--集合查询

  3. python pip源配置

    一.Linux版本: linux的文件存放在:~/.pip/pip.conf 二.windows版本: 在用户文件夹下创建pip目录,并在pip目录下创建pip.ini文件(%HOME%\pip\pi ...

  4. 前端 html head meta

    META(Metadata information) 提供有页面的元信息 例如:页面编码.刷新.跳转.针对搜索引擎和更新频道的描述和关键词 1.另外一种编码写法 <meta http-equiv ...

  5. [WorldWind学习]20.修改ShapeFileLayer类及托管D3D文字绘制方法

    PluginSDK\ShapeFileLayer.cs Line:1027char[] fieldDataChars = dbfReader.ReadChars(fieldHeaders[j].Fie ...

  6. 6.3 Controllers -- Managing Dependencies Between Controllers

    1. 有时候,特别是当嵌套资源的时候,我们需要两个controllers之间的某种连接.让我们拿这个router当做例子: app/router.js var Router = Ember.Route ...

  7. SpringData_Repository接口概述

    Repository 接口是 Spring Data 的一个核心接口,它不提供任何方法,开发者需要在自己定义的接口中声明需要的方法  public interface Repository<T, ...

  8. cocos-lua基础学习(七)Scene类学习笔记

    local scene = cc.Scene:create() cc.Director:getInstance():replaceScene( scene ) cc.Director:getInsta ...

  9. Bootstrap fileinput v3.0(ssm版)

    说明在上一个版本即Bootstrap fileinput v2.0(ssm版)的基础上,增加了多处都需要上传的需求 核心代码ArticleController.java package com.isd ...

  10. zw版【转发·台湾nvp系列Delphi例程】HALCON MoveRectangle

    zw版[转发·台湾nvp系列Delphi例程]HALCON MoveRectangle procedure TForm1.Button1Click(Sender: TObject);var img : ...