主頁 > 知識(shí)庫 > IE條件語句 IE hack大全

IE條件語句 IE hack大全

熱門標(biāo)簽:網(wǎng)站文章發(fā)布 智能手機(jī) 銀行業(yè)務(wù) 檢查注冊(cè)表項(xiàng) 美圖手機(jī) 呼叫中心市場(chǎng)需求 鐵路電話系統(tǒng) 服務(wù)器配置
Conditional comments work as follows:
復(fù)制代碼 代碼如下:

!--[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 IEbr />
![endif]-->
!--[if IE 6]>
According to the conditional comment this is IE 6br />
![endif]-->
!--[if IE 7]>
According to the conditional comment this is IE 7br />
![endif]-->
!--[if IE 8]>
According to the conditional comment this is IE 8br />
![endif]-->
!--[if IE 9]>
According to the conditional comment this is IE 9br />
![endif]-->
!--[if gte IE 8]>
According to the conditional comment this is IE 8 or higherbr />
![endif]-->
!--[if lt IE 9]>
According to the conditional comment this is IE lower than 9br />
![endif]-->
!--[if lte IE 7]>
According to the conditional comment this is IE lower or equal to 7br />
![endif]-->
!--[if gt IE 6]>
According to the conditional comment this is IE greater than 6br />
![endif]-->
!--[if !IE]> -->
According to the conditional comment this is not IEbr />
!-- ![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:
復(fù)制代碼 代碼如下:

!--[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.

標(biāo)簽:紅河 滄州 樂山 新疆 長(zhǎng)治 上海 沈陽 河南

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《IE條件語句 IE hack大全》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266