常用浏览器CSS hack汇总表及部分示例
1. 此汇总表中测试浏览器的版本为:
微软系统自带:IE6、 IE7、IE8
火狐:Firefox 3.6.6
Safari:Safari 5.0
谷歌浏览器:Chrome 6.0.458.1 dev
Opera浏览器:Opera 10.60
2. 其中,多数CSS hack是在selector{property:value;}基础上更改的。
selector代表CSS选择器,property代表CSS特性,value代表特性的值。
3. FF代表Firefox,Ch代表Chorme,Sa代表Safari,Op代表Opera
4. Q代表Quirks Mode,S代表Standards Mode。
5. Hack Type列的数字,指的是上面CSS hack的实现方式中的列表号。
1是指“利用浏览器对相同代码的解析和支持的不同实现的hack”,2是指以Firefox或Webkit特有的扩展样式实现的hack。
一定遵守CSS hack的三条原则。CSS hack是没有办法的时候才使用的解决兼容性问题的招术,是用兼容性问题去解决兼容性问题,无异于饮鸩止渴。切莫一有兼容性问题就使用,时刻记得改掉用CSS hack修补的问题。
下面列出常见几种浏览器的部分css hack。
1、IE条件注释 IE only
<!--[if lt IE 9]>Less Than IE9< ![endif]--> <!--[if lte IE 9]>Less Than or Equal IE9< ![endif]--> <!--[if IE]>IE only< ![endif]--> <!--[if IE 6]>IE6 only< ![endif]--> <!--[if IE 7]>IE7 only< ![endif]--> <!--[if gt IE 6]> Greater Than IE6< ![endif]--> <!--[if gte IE 6]> Greater Than or Equal IE6< ![endif]--> ...
2、CSS 选择器(Selector)Hack
/***** Selector Hacks ******/
/* IE6 and below */
* html .setest { color: red }
/* IE7 */
*:first-child+html .setest { color: blue }
/* IE7 */
*+html .setest { color: blue }
/* IE7, FF, Saf, Opera */
html>body .setest { color: green }
/* IE8, FF, Saf, Opera (Everything but IE 6,7) */
html>/**/body .setest { color: #ccc }
/* Everything but IE6-8 */
:root>.setest { color: #000 }
3、CSS 属性(Attribute)Hack
.attest{
color: blue !ie;
/* IE6, IE7 -- acts as an !important string after ! can be anything */
color/**/: green;/* Everything but IE6 */
color:#000; /* all */
+color:blue; /* ie7 */
_color:red; /*ie6注意ie7的"+"号hack写在前端,ietester中的ie6认识"+"*/
*color:#ccc; /* ie6-7 or #color: 777 */
color:#fafafa\9; /* all-ie */
color/*\**/: #ddd\9;/* IE7, IE8 */
color: #fefefe\0;/* IE8, IE9 */
}
Firefox CSS Hack
/* all firefox */
@-moz-document url-prefix(){
.fftest{color:red;}
}
/* Firefox only. 1+ */
.fftest, x:-moz-any-link { color: red }
/* Firefox 3.0+ */
.fftest, x:-moz-any-link, x:default { color: red }
Opera CSS Hack
/* Opera */
@media all and (-webkit-min-device-pixel-ratio:10000),
not all and (-webkit-min-device-pixel-ratio:0){
head~body .optest { color: red }
}
Safari CSS Hack
/* Safari */
@media screen and (-webkit-min-device-pixel-ratio:0){
.satest { color: red; }
}
/* Safari 2-3 */
html[xmlns*=""] body:last-child .satest { color: red; }
/* Safari 2 - 3.1 */
html[xmlns*=""]:root #.satest { color: red; }
Chrome及其它
/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:nth-of-type(1) .chtest { color: red }
/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:first-of-type .chtest { color: red }
/* saf3+, chrome1+ */
@media screen and (-webkit-min-device-pixel-ratio:0) {
.chtest { color: red }
}
/* iPhone / mobile webkit */
@media screen and (max-device-width: 480px) {
.chtest{ color: red }
}
- 固定链接:https://www.poorren.com/css-hack-table
- 文章标签:CSS,hack,样式表,浏览器,漏洞
- 扫二维码:常用浏览器CSS hack汇总表及部分示例
- 版权所有:除"转载分享"分类外,未经注明,均为原创、整理,转载请注明出处。
