针对Google Chrome谷歌浏览器的CSS hack
//update 2009.11.05
经honto提醒,这个方法已经不适用,因为Firefox3.5已经能解析这段代码。
Google于9月3号推出了浏览器Google Chrome,写前端效果的同志们又有得辛苦了,IE/FF/Opera/Safari/Google Chrome本来不太平的世界更混乱了。
所幸Google Chrome用的是与Safari一样的Webkit引擎,我们可以使用对safari相似的方式作css hack,写法为:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>a <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>关于Google Chrome的hack的具体用法</title> <style> body:nth-of-type(1) .me{color:#ff0000;} </style> </head> <body> <div class="me">我在Google Chrome底下是红色的!</div> </body> </html>
现在此hack已经不行了,FF3.5已经可以解析这段CSS了
@honto
看了一下,是这样的,多谢提醒。
hack的代码也可以这样写:
@media screen and (-webkit-min-device-pixel-ratio:0) { /* 针对chrome,Firefox下无效 */
#p{
color:#f00;
}
}
虽然不是合法css,但是可以用,嗯哼。
楼上的,能写到外部css里吗?我怎么没用?