IE条件语句 IE hack大全_其它综合

Conditional comments work as follows:

复制代码 代码如下:

<!--[if IE 6]>Special instructions for IE 6 here<![endif]-->
[code]

Their basic structure is the same as an HTML comment (<!-- -->). Therefore all other browsers will see them as normal comments and will ignore them entirely.
IE, though, has been programmed to recognize the special <!--[if IE]> syntax, resolves the ifand parses the content of the conditional comment as if it were normal page content.
Since conditional comments use the HTML comment structure, they can only be included in HTML files, and not in CSS files. I'd have preferred to put the special styles in the CSS file, but that's impossible. You can also put an entire new <link> tag in the conditional comment referring to an extra style sheet.
Example
Below I added a lot of conditional comments that print out messages according to your IE version.

Note however, that if you use multiple Explorers on one computer, the conditional comments will render as if all these Explorer versions are the highest Explorer version available on your machine (usually Explorer 6.0).

Test
Below are a few conditional comments that reveal the IE version you're using.

According to the conditional comment this is IE
According to the conditional comment this is IE 7
According to the conditional comment this is IE lower than 9
According to the conditional comment this is IE lower or equal to 7
According to the conditional comment this is IE greater than 6

Code
The syntax I use is:
[code]
<p class="accent">
<!--[if IE]>
According to the conditional comment this is IE<br />
<![endif]-->
<!--[if IE 6]>
According to the conditional comment this is IE 6<br />
<![endif]-->
<!--[if IE 7]>
According to the conditional comment this is IE 7<br />
<![endif]-->
<!--[if IE 8]>
According to the conditional comment this is IE 8<br />
<![endif]-->
<!--[if IE 9]>
According to the conditional comment this is IE 9<br />
<![endif]-->
<!--[if gte IE 8]>
According to the conditional comment this is IE 8 or higher<br />
<![endif]-->
<!--[if lt IE 9]>
According to the conditional comment this is IE lower than 9<br />
<![endif]-->
<!--[if lte IE 7]>
According to the conditional comment this is IE lower or equal to 7<br />
<![endif]-->
<!--[if gt IE 6]>
According to the conditional comment this is IE greater than 6<br />
<![endif]-->
<!--[if !IE]> -->
According to the conditional comment this is not IE<br />
<!-- <![endif]-->
</p>

Note the special syntax:

gt: greater than
lte: less than or equal to
Also note the last one. It has a different syntax, and its contents are shown in all browsers that are not IE:

复制代码 代码如下:

<!--[if !IE]> -->

CSS hack?
Are conditional comments CSS hacks? Strictly speaking, yes, since they can serve to give special style instructions to some browsers. However, they do not rely on one browser bug to solve another one, as all true CSS hacks do. Besides, they can be used for more than CSS hacks only (though that rarely happens).

Since conditional comments are not based on a browser hack but on a deliberate feature I believe they are safe to use. Sure, other browsers could implement conditional comments, too (though as yet none have done so), but they're unlikely to react to the specific query <!--[if IE]>.

I use conditional comments, though sparingly. First I see if I can find a real CSS solution to an Explorer Windows problem. If I can't, though, I don't hesitate to use them.

Comment tag
A reader told me IE also supports the (non-standard) <comment> tag.

<p>This is <comment>not</comment> IE.</p>

This isIE.

This tag might be a replacement for the !IE conditional comment.

时间: 2024-09-19 09:16:16

IE条件语句 IE hack大全_其它综合的相关文章

电子邮件 退信原因大全_其它综合

退信提示:"Invalid User"."User not found"."User unknown" 退信原因:对方用户不存在,由于发件人中的信箱地址有错误,发送服务器无法找到要投递的邮件地址. 解决方法:我们只要确认自己填写的地址是不是有错误,正确无误后再重新投递. 退信提示:"Quota"."Hard limit"."Storage allocation" 退信原因:对方邮箱已经满

JavaScript中的条件判断语句使用详解_基础知识

 在写一个程序,可能有一种情况,当你需要采用一个路径出给定两个路径.所以,需要使用条件语句,让程序来做出正确的决策和执行正确的行动. JavaScript支持其用于执行根据不同的条件不同的操作条件语句.在这里,我们将解释if..else语句. JavaScript支持if..else语句的形式如下:     if 语句     if...else 语句     if...else if... 语句. if 语句: if语句是基本的控制语句,它允许JavaScript来作出决定,有条件地执行语句.

ASP基础入门第四篇(脚本变量、函数、过程和条件语句)_应用技巧

       在上一篇小编向大家简要介绍了 ASP 脚本语言之一 VBScript 的一些基本常识,本期将继续给大家讲解 VBScript 的脚本编写方法,并通过展示 VBScript 在 ASP 程序编写过程中的一系列实例使大家对 VBScript 有更进一层的理解.   函数和过程一样都是命名了的代码块,但它们却有很大的区别,过程完成程序任务,函数则返回值.我们可以这样理解,过程象一个完整的句子,而函数则象一个单词.举个例子,当你想获取某个数的平方根,你只要将该数传给 VBScript 的

Javascript基础教程之if条件语句_基础知识

if 是常用语法之一,其格式如下 if(coditon) statement1 (else statement2) 其中,coditon可以是任何表达式,甚至不比是真正的布尔值,因为JavaScript会将其自动转化为布尔值. 如果条件执行结果为true,则执行statement1,如果条件为false,则执行结果statment2,(如果statement2存在,则else不是必须的) 每个条件语句可以是单行代码,也可以是代码块.以下是简单的举例 复制代码 代码如下:     var iNum

SQL Server 的 SQL 语句导入导出大全_MsSql

MS SQL Server数据库SQL语句导入导出大全,包括与其他数据库和文件的数据的导入导出.     /*******  导出到excel     EXEC master..xp_cmdshell 'bcp SettleDB.dbo.shanghu out c:temp1.xls -c -q -S"GNETDATA/GNETDATA" -U"sa" -P""'     /***********  导入Excel     SELECT *   

SQL Server 的 SQL 语句导入导出大全

MS SQL Server数据库SQL语句导入导出大全,包括与其他数据库和文件的数据的导入导出. /*******  导出到excel     EXEC master..xp_cmdshell 'bcp SettleDB.dbo.shanghu out c:temp1.xls -c -q -S"GNETDATA/GNETDATA" -U"sa" -P""'     /***********  导入Excel     SELECT *     FR

代码-C++条件语句问题!!!!!

问题描述 C++条件语句问题!!!!! 我用两个if条件语句执行两种不同情况的代码,现在想在第一个if条件语句执行完后,判断是否满足一个条件,如果满足,就跳出,不再执行:但是第二个if条件语句正常执行 .我在中间加了if(....)break;的语句,结果第二部分的条件语句不再执行了,请问是为什么?该如何解决??请大家帮个忙! 解决方案 可以设置一个标志变量: int flag=0; if(条件1){ ...; flag=1;} if(条件2 && flag!=1) {...} 解决方案二

ie兼容-关于IE条件语句的一点疑惑

问题描述 关于IE条件语句的一点疑惑 经常在网站头部看到类似于这样的IE条件注释: <!--[if IE 7 ]><html lang=""zh"" id=""ne_wrap"" class=""no-js ie7""><![endif]--> 虽然能够理解该注释语法:在浏览器版本为ie7时,应用该代码,非ie浏览器则只把其当做一条注释而忽略掉.但不太

使用条件语句

条件|语句 控制程序执行 使用条件语句和循环语句可以控制 Script 的流程.使用条件语句可以编写进行判断和重复操作的 VBScript 代码.在 VBScript 中可使用以下条件语句: If...Then...Else 语句 Select Case 语句 使用 If...Then...Else 进行判断 If...Then...Else 语句用于计算条件是否为 True 或 False,并且根据计算结果指定要运行的语句.通常,条件是使用比较运算符对值或变量进行比较的表达式.有关比较运算符的