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;
}
测试文件见附件。
- 12:27
- 浏览 (885)
- 评论 (1)
- 分类: html/css/js
- 发布在 javascript研究小组 圈子
- 相关推荐
评论
playfish
2008-04-21
原本对于hack也有学习,但是总觉得不好用,写很麻烦。我觉得使用js来完成是最好的方式。目前用过的jbrowser就不错,jquery的一个插件。在页面上引入这个js后,不同浏览器的css只要.ie6 #id .mozina ..class就可以了。脚本里面直接if(jbrowser.ie)。这种方式最轻松安逸,完全不需要记忆任何的hack。。
发表评论
- 浏览: 183892 次
- 性别:

- 来自: 安徽

- 详细资料
搜索本博客
我的相册
分形大厦
共 10 张
共 10 张
最近加入圈子
链接
最新评论
-
Person对象中"姓-名"的 ...
jasongreen 写道都别装了 写道数据库还是叫first / last n ...
-- by 都别装了 -
Person对象中"姓-名"的 ...
我搞不懂的是老外为什么一定要把first name和last name分开,直接 ...
-- by quaff -
Person对象中"姓-名"的 ...
都别装了 写道数据库还是叫first / last name 在页面显示的时候做 ...
-- by jasongreen -
Person对象中"姓-名"的 ...
数据库还是叫first / last name 在页面显示的时候做i18n不就好 ...
-- by 都别装了 -
Person对象中"姓-名"的 ...
e文 显示时候就颠倒下顺序不就得了。。
-- by 叶子






评论排行榜