CSS-经常使用hack

尽可能少用或者不用hackcss

方法一:IE条件注释法:

01.只在IE下生效html

<!-- [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/!关键字进行注释;spa

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

例如:表示IE版本大于6htm

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

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

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

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

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

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

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

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

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

针对safari浏览器;

elelent{
    [;color: red;  /*只在safari下生效*/
}
相关文章
相关标签/搜索