標籤:style blog http io color ar os 使用 java
沒估計錯的話舊版瀏覽器都是不識別這些新增的標籤所以都是用行內元素來處理解決的,所以,有一個解決辦法的突破口就是讓它變成塊狀元素就不會處於同一行了,這樣在新舊瀏覽器都是可以顯示同樣的效果,再者就是讓瀏覽器識別標籤,需要新增標籤,具體解決辦法是:
IE8/IE7/IE6支援通過document.createElement方法產生的標籤,可以利用這一特性讓這些瀏覽器支援HTML5新標籤,代碼如下:
document.createElement(‘新標籤’); / /新增建立新標籤
方式一:Coding JavaScript
<!--[if lt IE9]>
<script>
(function() { if (!
/*@[email protected]*/
0) return;
var e = "abbr, article, aside, audio, canvas, datalist, details, dialog,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,time,video".split(‘, ‘);
var i= e.length;
while (i--){ document.createElement(e[i])
}
})()
</script>
<![endif]—>
將上代碼複製到head部分,記住一定要是head部分(因為IE必須在元素解析前知道這個元素,所以這個js檔案不能在其他位置調用,否則失效)
方式二:使用Google的html5shiv包(推薦)
<!--[if lt IE9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
當然,你也可以把代碼拿出來自己看著辦:
(function(){if(!/*@[email protected]*/0) return;
var e ="abbr,article,aside,audio,canvas,datalist,details,dialog,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,time,video".split(‘,‘),i=e.length;
while(i--){document.createElement(e[i])}})()
最後在css裡面加上這段:
/*html5*/ article,aside,dialog,footer,header,section,footer,nav,figure,menu{display:block}
主要是讓這些html5標籤成塊狀,像div那樣。
好了,簡單吧,一句話概括就是:引用html5.js 使html5標籤成塊狀.
--------------------------------
參考雷鋒網的原始碼執行個體:
<參考:http://blog.csdn.net/ptyzhu/article/details/19477695 & http://www.th7.cn/web/html-css/201404/29228.shtml>
讓ie瀏覽器支援html5新標籤的解決方案(使用html5shiv)