CSS Hack

CSS Hack是我们解决浏览器兼容性(尤其是IE各版本)问题的常用手段。CSS Hack的手法可以说是五花八门,使用时经常混淆。下面是一个汇总,以便查阅。

js代码

/***** Selector Hacks ******/
   
/* IE6及更低版本浏览器 */
* html  #uno  { color: red }
   
/* IE7 */
*:first-child+html  #dos { color: red } 
   
/* IE7, FF, Saf, Opera  */
html>body  #tres { color: red }
   
/* IE8, FF, Saf, Opera (除了IE 6、7的所有浏览器) */
html>/**/body  #cuatro { color: red }
   
/* Opera 9.27 and below, safari 2 */
html:first-child  #cinco { color: red }
   
/* Safari 2-3 */
html[xmlns*=""] body:last-child  #seis { color: red }
   
/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:nth-of-type(1)  #siete { color: red }
   
/* safari 3+, chrome 1+, opera9+, ff 3.5+ */
body:first-of-type  #ocho {  color: red }
   
/* saf3+, chrome1+ */
@media screen and (-webkit-min-device-pixel-ratio:0) {
 #diez  { color: red  }
}
   
/* iPhone / mobile webkit */
@media screen and (max-device-width: 480px) {
 #veintiseis { color: red  }
}
   
   
/* Safari 2 - 3.1 */
html[xmlns*=""]:root  #trece  { color: red  }
   
/* Safari 2 - 3.1, Opera 9.25 */
*|html[xmlns*=""]  #catorce { color: red  }
   
/* 除了ie 6-8的所有浏览器 */
:root *>  #quince { color: red  }
   
/* IE7 */
*+html  #dieciocho {  color: red }
   
/* Firefox. 1+ */
#veinticuatro,  x:-moz-any-link  { color: red }
   
/* Firefox 3.0+ */
#veinticinco,  x:-moz-any-link, x:default  { color: red  }
   
/* FF 3.5+ */
body:not(:-moz-handler-blocked)  #cuarenta { color: red; }
   
   
/***** Attribute Hacks ******/
   
/* IE6 */
#once { _color: blue }
   
/* IE6, IE7 */
#doce { *color: blue; /* o或者 #color: blue */ }
   
/* 所有浏览器,除了 IE6 */
#diecisiete { color/**/: blue }
   
/* IE6, IE7, IE8 */
#diecinueve { color: blue\9; }
   
/* IE7, IE8 */
#veinte { color/*\**/: blue\9; }
   
/* IE6, IE7 -- 和!important作用相同 */
#veintesiete { color: blue !ie; } /* 感叹号后边可以是任意字符串 */
   
/* IE8, IE9 */
#anotherone  {color: blue\0/;} /* 必须放在所有规则的最后面 */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值