在网页中使用条件判断和区分浏览器

在网站开发中我们经常会考虑在一些主流的浏览器的兼容性,这些浏览器如:IE6、IE7、Firefox2.x、Firefox3.x,以及Opera的一些版本。

相对这些浏览器Firefox的各版本最为标准。网站开发人员经常在Firefox和IE之间来回切换查看效果,怎样才能更省力更高效,我们可以用Firefox为主来制作网页或css,对于IE存在的问题,我们使用另一个css样式表或HTML标签。

条件语法如下:

确定的

   <!--[if 条件]>
HTML <![endif]-->

否定的

   <!--[if !条件]>
<![IGNORE[--><![IGNORE[]]> HTML <!--<![endif]-->

条件可以是:

IE
IE的任意版本

lt IE 版本
版本小于版本?

lte IE 版本
版本小于或等于版本?

IE 版本
唯一指定的版本

gte IE 版本
版本大于或等于版本

gt IE 版本
版本大于版本

代表IE的版本:5 , 5.5 , 6 , 7

评论

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 允许HTML标签:<a> <img> <em> <del> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <h3> <h4> <h5> <h6>
  • 自动断行和分段。
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

更多关於格式化选项的信息

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.