2008-04-20
html/javascript/css 注释表达式详解
关键字: css hack, ie
浏览器之间的兼容是个问题,而IE的兼容性尤其严重。下面是我搜集的一些处理html/js/css兼容性问题的好方法。
html 条件注释
javascript 编译注释
javascript编译常量
http://www.javascriptkit.com/javatutors/conditionalcompile2.shtml
css !important.
!importan 在firefox,ie7中支持,在ie6中不支持。
ie6支持 * html 前缀 ,ie7 支持 *+html 前缀,firefox不支持。
ie支持css expression,在firefox中是不支持的。
#testcss {/*any*/
background-color:red;
}
* html #testcss {/*ie6*/
background-color:green;
}
*+html #testcss {/*ie7*/
background-color:yellow;
}
测试文件见附件。
html 条件注释
<html> <body> <!--[if IE]> 根据条件判断,这是Internet Explorer<br /> <![endif]--> <!--[if IE 5]> 根据条件判断,这是Internet Explorer 5<br /> <![endif]--> <!--[if IE 5.0]> 根据条件判断,这是Internet Explorer 5.0<br /> <![endif]--> <!--[if IE 5.5]> 根据条件判断,这是Internet Explorer 5.5<br /> <![endif]--> <!--[if IE 6]> 根据条件判断,这是Internet Explorer 6<br /> <![endif]--> <!--[if gte IE 5]> 根据条件判断,这是Internet Explorer 5 或者更高<br /> <![endif]--> <!--[if lt IE 6]> 根据条件判断,这是版小于6的Internet Explorer<br /> <![endif]--> <!--[if lte IE 5.5]> 根据条件判断,这是Internet Explorer 5.5或更低<br /> <![endif]--> </body> </html>
javascript 编译注释
引用
<script type="text/javascript">
/*@cc_on
document.write('IE 4+ browser support @cc_on<br>');
/*@if (@_jscript_version >= 5)
document.write("IE Browser that supports JScript 5+<br>");
@elif (@_jscript_version >= 4)
document.write("IE Browser that supports JScript 4+<br>");
@else @*/
document.write("Non IE Browser or lower version IE<br>");
/*@end
@*/
</script>
/*@cc_on
document.write('IE 4+ browser support @cc_on<br>');
/*@if (@_jscript_version >= 5)
document.write("IE Browser that supports JScript 5+<br>");
@elif (@_jscript_version >= 4)
document.write("IE Browser that supports JScript 4+<br>");
@else @*/
document.write("Non IE Browser or lower version IE<br>");
/*@end
@*/
</script>
javascript编译常量
http://www.javascriptkit.com/javatutors/conditionalcompile2.shtml
css !important.
!importan 在firefox,ie7中支持,在ie6中不支持。
引用
<div style="color: red !important; color: blue;">
IE7,firefox中显示为红色文字,IE6中显示为蓝色文字
</div>
IE7,firefox中显示为红色文字,IE6中显示为蓝色文字
</div>
ie6支持 * html 前缀 ,ie7 支持 *+html 前缀,firefox不支持。
ie支持css expression,在firefox中是不支持的。
引用
#testcss {/*any*/
background-color:red;
}
* html #testcss {/*ie6*/
background-color:green;
}
*+html #testcss {/*ie7*/
background-color:yellow;
}
测试文件见附件。
- by jasongreen
- 浏览 (897)
- 评论 (1)
- 相关推荐


评论