欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

HTML5 声明兼容IE的写法

程序员文章站 2023-12-13 08:50:22
无意中看到百度的页面代码,想到了一种声明写法,需要的朋友可以参考下。... 11-05-16...
<!doctype html>是html5的声明,主流的游览器中只有ie8及以下版本不支持,这样ie会进入quirks模式。但之后的声明可以强制指定ie的呈现模式,所以<!doctype html>声明对ie就无影响。

html5并没有xhtml那么严格,对于一般的xhtml页面,基本都不通完全通过w3c验证标准,而改为html5声明后基本都能过。


复制代码
代码如下:

<!doctype html>
<!–[if ie]>
<meta http-equiv=”x-ua-compatible” content=”ie=8′ />
<![endif]–>
<!–[if ie 7]>
<meta http-equiv=”x-ua-compatible” content=”ie=7′ />
<![endif]–>
<!–[if ie 6]>
<meta http-equiv=”x-ua-compatible” content=”ie=6′ />
<![endif]–>

关于x-ua-compatible
目前绝大多数网站都用

<meta http-equiv="x-ua-compatible" content="ie=emulateie7" >

来作为ie8的兼容方法,虽然微软将ie向标准迈进了一大步,而事实上ie8还存在一系列渲染的奇怪现象是不争的事实。
谁让ie6那么多呢,或许2014年以后我们可以有更多的时间去关心ie8,而不是ie6或者ie7。
在x-ua-compatible中可用的方法有:

复制代码
代码如下:

<meta http-equiv="x-ua-compatible" content="ie=5" >
<meta http-equiv="x-ua-compatible" content="ie=7" >
<meta http-equiv="x-ua-compatible" content="ie=8" >
<meta http-equiv="x-ua-compatible" content="ie=edge" >
[html]
其中最后一行是永远以最新的ie版本模式来显示网页的。
另外加上
[code]
<meta http-equiv="x-ua-compatible" content="ie=emulateie7" >
<meta http-equiv="x-ua-compatible" content="ie=emulateie8" >

而使用,emulate模式后则更重视<!doctype>

所以目前来说,云下载还是推荐以下

复制代码
代码如下:

<meta http-equiv="x-ua-compatible" content="ie=emulateie7" >

为首选。

上一篇:

下一篇: