Skip to content

让IE支持HTML5标签

HTML5标签无法在IE下面无法被识别,自然也就无法渲染样式,应该来讲是IE8以下的版本。好了,今天说的HTML5 Shiv主要作用就是让IE正常识别HTML5标签,这个方法是来源于http://code.google.com/p/html5shiv/。但是注意,这只里只强制IE正常的渲染样式,其标签自身功能还是无法呈现的。

HTML5 Shiv原理

IE下如果遇到无法识别的标签,那只要在DOM创建前使用document.createElement就可以强制渲染该标签样式。例如:

<html>
<head>
<style>nav a { color:#F50; }</style>
</head>
<body>
<nav><a href="home.html">Home</a></nav>
</body>
</html>

在IE下面是链接颜色是无法渲染的。

HTML5 Shiv使用

只要在head下(必须是head)引用以下脚本,那么IE就能正常渲染样式。

<!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->

相关日志

Categories: 技术.

Tags:

Comment Feed

No Responses (yet)



Some HTML is OK

or, reply to this post via trackback.

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word