史上最全的css hack(ie6-9,firefox,chrome,opera,safari)
来源:互联网 发布:搜狐媒体大厦淘宝地址 编辑:程序博客网 时间:2024/06/05 15:26
在这个浏览器百花争鸣的时代,作为前端开发的我们为了我们漂亮的设计能适应各个浏览器可为煞费苦心,主要体现在javascript和css上面。javascript我这次就不谈了,先说说css。 上面这段代码大家可以直接copy出来,保存成html在各浏览器试试。下面我来分析下:
为了适应不同浏览器不同的版本(版本主要就ie来说),ie这朵奇葩现在我们要兼容6-9,它的10也快出来了。。。在ie下我们可以写条件注释来区分ie和其他浏览器,以及ie的版本,这些请大家自行google。这篇文章主要讨论的是css hack。下面废话补多说了,直接上代码
<!DOCTYPE html>
<html>
<head>
<title>Css Hack</title>
<style>
#test
{
width:300px;
height:300px;
background-color:blue; /*firefox*/
background-color:red\9; /*all ie*/
background-color:yellow\0; /*ie8*/
+background-color:pink; /*ie7*/
_background-color:orange; /*ie6*/
}
:root #test { background-color:purple\9; } /*ie9*/
@media all and (min-width:0px){ #test {background-color:black\0;} } /*opera*/
@media screen and (-webkit-min-device-pixel-ratio:0){ #test {background-color:gray;} } /*chrome and safari*/
</style>
</head>
<body>
<div id="test">test</div>
</body>
</html>
<html>
<head>
<title>Css Hack</title>
<style>
#test
{
width:300px;
height:300px;
background-color:blue; /*firefox*/
background-color:red\9; /*all ie*/
background-color:yellow\0; /*ie8*/
+background-color:pink; /*ie7*/
_background-color:orange; /*ie6*/
}
:root #test { background-color:purple\9; } /*ie9*/
@media all and (min-width:0px){ #test {background-color:black\0;} } /*opera*/
@media screen and (-webkit-min-device-pixel-ratio:0){ #test {background-color:gray;} } /*chrome and safari*/
</style>
</head>
<body>
<div id="test">test</div>
</body>
</html>
background-color:blue; 各个浏览器都认识,这里给firefox用;
background-color:red\9;\9所有的ie浏览器可识别;
background-color:yellow\0; \0 是留给ie8的,但笔者测试,发现最新版opera也认识,汗。。。不过且慢,后面自有hack写了给opera认的,所以,\0我们就认为是给ie8留的;
+background-color:pink; + ie7定了;
_background-color:orange; _专门留给神奇的ie6;
:root #test { background-color:purple\9; } :root是给ie9的,网上流传了个版本是 :root #test { background-color:purple\0;},呃。。。这个。。。,新版opera也认识,所以经笔者反复验证最终ie9特有的为:root 选择符 {属性\9;}
@media all and (min-width:0px){ #test {background-color:black\0;} } 这个是老是跟ie抢着认\0的神奇的opera,必须加个\0,不然firefox,chrome,safari也都认识。。。
@media screen and (-webkit-min-device-pixel-ratio:0){ #test {background-color:gray;} }最后这个是浏览器新贵chrome和safari的。
好了就这么多了,特别注意以上顺序是不可以改变的。css hack虽然可以解决个浏览器之间css显示的差异问题,但是毕竟不符合W3C规范,我们平时写css最好是按照标准来,这样对我们以后维护也是大有好处的,实在不行再用。
如果给位看官有更好的css hack写法或者本文有不妥之处,欢迎留言,第一次写文章,请轻砸。
原文:cnblogs
- [HTML][CSS]史上最全的css hack(ie6-9,firefox,chrome,opera,safari)
- css hack(ie6-9,firefox,chrome,opera,safari)
- css hack(ie6-9,firefox,chrome,opera,safari)
- css hack(ie6-9,firefox,chrome,opera,safari)
- css hack(ie6-9,firefox,chrome,opera,safari)
- Css Hack(ie6-9,firefox,chrome,opera,safari)
- 史上最全的css hack(ie6-9,firefox,chrome,opera,safari)
- 史上最全的css hack(ie6-9,firefox,chrome,opera,safari)
- 史上最全的css hack(ie6-9,firefox,chrome,opera,safari)
- 史上最全的css hack(ie6-9,firefox,chrome,opera,safari)
- 史上最全的css hack(ie6-9,firefox,chrome,opera,safari)
- 史上最全的css hack(ie6-9,firefox,chrome,opera,safari)
- 史上最全的CSS hack方式一览(解决IE6-IE11,Firefox/Safari/Opera/Chrome兼容问题)
- 最全的css hack(ie6-9,firefox,chrome,opera,safari)
- css hack[ie6-9,firefox,chrome,opera,safari]写法
- Chrome、Firefox、IE6|IE7|IE8、Opera、Safari CSS HACK
- 兼容 ie6-9,firefox,chrome,opera,safari css
- CSS IE6/7/8, Firefox, Safari, Chrome, Opera Hack使用简要归纳
- jdbc2_DriverManager_Connection
- 将同一节点上运行的进程划分到同一个通信域
- Diary in 20121106
- 请编写一个关于星期几的枚举WeekDay
- 搜狗输入法几个实用技巧
- 史上最全的css hack(ie6-9,firefox,chrome,opera,safari)
- 史上最全的css hack(ie6-9,firefox,chrome,opera,safari)
- 请使用sun 内省api得到某一个bean的所有属性,并操作bean的其中一个属性(给属性赋值,以及得到属性的值
- 优化SQL查询:如何写出高性能SQL语句
- Core Mappings in Action-Oriented Web Framework
- 请使用beanUitls框架操作bean的属性,然后会自定义转换器
- Smack类库详细介绍
- extjs4_treestore_s2sh整合,不容易啊,折腾2天
- 笔记-2003-Chinese Word Segmentation as LMR Tagging