CSS-常用hack

尽量少用或者不用hack

方法一:IE条件注释法:

01.只在IE下生效

<!-- [if IE]>
<link type="text/css" href="text.css" rel="stylesheet" />
<![endif] -->

02.只在IE6下生效

<!-- [if IE 6]>
<link type="text/css" href="text.css" rel="stylesheet" />
<![endif] -->

03.如果想针对某个范围以内版本的IE进行hack,可以结合lte/lt/gte/gt/!关键字进行注释;

lte:小于等于;
lt:小于;
gte:大于等于;
gt:大于;
!:不等于; 

例如:表示IE版本大于6

<!-- [if gt IE 6]>
<link type="text/css" href="text.css" rel="stylesheet" />
<![endif] -->

方法二:选择器前缀写法:

在css选择器前加一些只有特定浏览器才能识别的前缀。

"*html"前缀只对IE6生效,"*+html"只对IE7生效;

<style type="text/css">
*html .test{width: 120px;}  /*只在IE6下生效*/
*+html .test{width: 120px;}  /*只在IE7下生效*/
</style>

方法三:样式属性前缀写法:

在样式的属性名前加一些只有特定浏览器才能识别的前缀。

"_"前缀只对IE6生效,"*"对IE6/IE7生效;

<style type="text/css">
.test{
    _width: 120px;  /*只在IE6下生效*/
    *width: 120px;  /*对IE6/IE7生效*/
}
</style>

针对safari浏览器;

elelent{
    [;color: red;  /*只在safari下生效*/
}

 

posted @ 2014-04-17 14:18  白小虫  阅读(169)  评论(0编辑  收藏  举报