在不同的浏览器使用不同的css样式,解决浏览器兼容问题
区别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样式,解决浏览器兼容问题的更多相关文章
- 如何让不同浏览器调用不同的CSS样式
如何让不同浏览器调用不同的CSS样式 由 于对W3C标准支持程度的不同,往往导致同一个CSS样式表在各种Web浏览器中的呈现大相径庭.以目前市场占有率最高的两个浏览器Microsoft Interne ...
- CSS样式 解决文字过长显示省略号问题
一.CSS样式 解决文字过长显示省略号问题 1.一般样式 一般 css 样式,当宽度不够时,可能会出现换行的效果.这样的效果在某些时候肯定是不行的,可以修改 css 样式来解决这个问题. <!D ...
- CSS Hack解决浏览器IE部分属性兼容性问题
1.Css Hack 不同厂商的流览器或某浏览器的不同版本(如IE6-IE11,Firefox/Safari/Opera/Chrome等),对CSS的支持.解析不一样,导致在不同浏览器的环境中呈现出不 ...
- 如何根据不同的浏览器写不同的css样式达到兼容
做前端静态页面的时候总是发现,ie的兼容性很差,总会出点问题.然后就去改代码 ,改完以后 又发现 火狐 谷歌又挂了,这可咋整. 后来发现做个判断吧 哪里有问题哪里就做个判断呗 ,咋判断呢,这么 ...
- 怎样使一个宽为200px和高为200px的层垂直居中于浏览器中?写出CSS样式代码。
div{ height:100px; width:100px; position:absolute; top:50%; width:50%; margin-letf:-100px; margin-to ...
- js的append拼接html丢失css样式解决
htmlApp += "<li id='leftli"+lunci+"'>"; htmlApp += "<span id='left ...
- CSS样式总结
CSS: Cascading Style Sheet,层叠样式表 Css由三部分组成:选择符.样式属性.值: 基本语法:选择符 {样式属性:值:样式属性:值.....} 一,选择器 常用的选择器有:标 ...
- 前端之css样式(选择器)。。。
一.css概述 CSS是Cascading Style Sheets的简称,中文称为层叠样式表,对html标签的渲染和布局 CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明. 例如 二.c ...
- 初始化 CSS 样式
为什么要初始化 CSS 样式 因为浏览器的兼容问题,不同浏览器对有些标签的默认值是不同的,如果没对 CSS 初始化往往会出现浏览器之间的页面显示差异. 当然,初始化样式会对 SEO 有一定的影响,但鱼 ...
随机推荐
- nginx详解之语法规则
1.location [=|~|~*|^~] /uri/ { … } location = / { # 精确匹配 / ,主机名后面不能带任何字符串 [ configuration A ] ...
- Ubuntu安装pycurl
转自:https://blog.csdn.net/qq_23729557/article/details/78836547 在Ubuntu 16.04上安装pycurl时大致会遇到一下两个问题: 在使 ...
- formset批量处理form表单数据
Formset(表单集)是多个表单的集合.Formset在Web开发中应用很普遍,它可以让用户在同一个页面上提交多张表单,一键添加多个数据 class StudentStudyRecordModel( ...
- PHP debug_backtrace() 函数打印调用处的调试信息
http://php.net/manual/zh/function.debug-backtrace.php debug_backtrace (PHP 4 >= 4.3.0, PHP 5, PHP ...
- uva The Tower of Babylon[LIS][dp]
转自:https://mp.weixin.qq.com/s/oZVj8lxJH6ZqL4sGCXuxMw The Tower of Babylon(巴比伦塔) Perhaps you have hea ...
- cocos-lua基础学习(10)scheduler类学习笔记
local scheduler = cc.Director:getInstance():getScheduler() local function shouldNotCrash(dt) end loc ...
- LA 4287 有相图的强连通分量
大白书P322 , 一个有向图在添加至少的边使得整个图变成强连通图, 是计算整个图有a个点没有 入度, b 个点没有出度, 答案为 max(a,b) ; 至今不知所云.(求教) #include &l ...
- Python tricks(1) -- 动态定义一个新变量
python是动态语言, 无需声明变量即可使用. 传递一个tuple, list或者dict等等方式, 有时候这种方式的使用不是很好. 对于tuple和list来说都是用下标的访问方式(即使用[]), ...
- 【运维技术】kafka三实例集群环境搭建及测试使用
kafka三实例集群环境搭建及测试使用 单机搭建分为两部分:1. 软件安装启动 2. 软件配置 软件安装启动: # 切换到目录 cd /app # 获取kafka最新安装包,这边使用的是镜像地址,可以 ...
- bzoj1607 / P2926 [USACO08DEC]拍头Patting Heads
P2926 [USACO08DEC]拍头Patting Heads 把求约数转化为求倍数. 累计每个数出现的个数,然后枚举倍数累加答案. #include<iostream> #inclu ...