HTML5的語義化標簽以及屬性,可以讓開發者非常方便地實現清晰的web頁面布局,加上CSS3的效果渲染,快速建立豐富靈活的web頁面顯得非常簡單。
HTML5的新標簽元素有:
- <header>定義頁面或區段的頭部;
- <footer>定義頁面或區段的尾部;
- <nav>定義頁面或區段的導航區域;
- <section>頁面的邏輯區域或內容組合;
- <article>定義正文或一篇完整的內容;
- <aside>定義補充或相關內容;
方式一:Coding JavaScript
<!--[if lt IE 9]>
<script>
(function() {
if (!
/*@cc_on!@*/
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]-->
第二種方法:使用Google的html5shiv包(推薦)
<!--[if lt IE9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]-->
但是不管使用以上哪種方法,都要初始化新標簽的CSS.因為HTML5在默認情況下表現為內聯元素,對這些元素進行布局我們需要利用CSS手工把它們轉為塊狀元素方便布局
/*html5*/
article,aside,dialog,footer,header,section,footer,nav,figure,menu{display:block}
但是如果ie6/7/8 禁用腳本的用戶,那么就變成了無樣式的"白板"網頁,我們該怎么解決呢?
我們可以參照facebook的做法,即引導用戶進入帶有noscript標識的 “/?_fb_noscript=1”頁面,用 html4 標簽替換 html5 標簽,這要比為了保持兼容性而寫大量 hack 的做法更輕便一些。
<!--[if lte IE 8]>
<noscript>
<style>.html5-wrappers{display:none!important;}</style>
<div class="ie-noscript-warning">您的瀏覽器禁用了腳本,請<a href="">查看這里</a>來啟用腳本!或者<a href="/?noscript=1">繼續訪問</a>.
</div>
</noscript>
<![endif]-->

