safari 的css hack

十一月 25, 2008 by zhanbin  
分类:web标准

safari 是apple公司的浏览器产品,虽然用的人不多,并且在绝大部分情况下safari对css的解释和firefox没什么差别,但是就那么一点点的区别可能会让很多精益求精的人挠头。所以有时候还是需要些hack来区分safari同其他浏览器。

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
< !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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
 
#example{ color:red;font-size:50px;} /* ff有效 */
/*\*/
 
html*#example {
[color:black;color:blue;/* Safari有效 */]
color:green;/* IE有效 */
[font-size:12px;font-size:20px;]
 font-size:12px;
}/**/
 
-->
</style>
 
</head>
 
<body>
<div id="example">IE下 绿色 12像素  
safari 下蓝色 20像素
firefox 红色 50像素</div>
 
</body>
</html>

方括号中的属性在safari下可以识别,但是需要注意的一点是方括号中的属性需要同时写2个,第一个是不显现的,第二个才是要在safari下显现的属性。

例子中:
IE下显示为 绿色12像素
safari下显示为 蓝色20像素
firefox下显示为 红色50像素

demo

相关内容

评论



让我知道你的想法:(支持Gravatar头像服务)