浏览器兼容性问题(一)HTML5标签在 IE 6,IE 7, IE 8不兼容问题

387 阅读1分钟

##HTML5标签在 IE 6,IE 7, IE 8不兼容问题 二话不说就是讲代码,在html5里面新增了很多标签,为了更好的表达语意,例如header、section、footer等标签,但是在 IE 6 ,IE 7,IE 8 种可能并不支持这些标签。看代码如下:

<!DOCTYPE html>
<html lang="en">    
<head>    
  <meta charset="UTF-8">
</head>
<body>   
     <header>header</header>   
     <section>section</section>   
     <footer>footer</footer>
</body>
</html>

我们给这几个标签添加css样式

<style>   
 header{       
   width:60px;       
   height:50px;           
   color: aqua;       
   background: hotpink;   
 }   
<!---另外两个略-->
......
</style>

在 IE 9 的环境下:

Paste_Image.png

在chrome,火狐的环境下也能正常显示:

Paste_Image.png

在IE 6,IE 7 环境下:

Paste_Image.png

解决办法:通过 DOM 创建 HTML5 现对应的标签,代码如下:

<script type="text/javascript">   
       document.createElement("header");   
       document.createElement("section");    
       document.createElement("footer");
</script>

css细节注意,如果HTML5的新标签是块元素,则需要设置display样式,如header标签

header{     
      display: block; 
}

为了更好的解决HTML5新标签兼容问题,把一下代码拷贝即可,或者把js文件下载下来。

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

该笔记是以前写的,fuck IE一下,现在估计大家都解脱了?