本章講解如何從一張典型的 HTML4 頁(yè)面遷移至典型的 HTML5。
成都創(chuàng)新互聯(lián)公司主要從事成都網(wǎng)站建設(shè)、網(wǎng)站制作、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)漢陽(yáng),十載網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來(lái)電咨詢建站服務(wù):028-86922220
本章演示如何把一張已有的 HTML4 頁(yè)面轉(zhuǎn)換為 HTML5 頁(yè)面,在不破壞如何原始內(nèi)容和結(jié)構(gòu)的情況下。
注釋:您可以使用相同的技巧從 HTML4 以及 XHTML 遷移至 HTML5。
典型的 HTML4 典型的 HTML5 <div id="header"> <header> <div id="menu"> <nav> <div id="content"> <section> <div id="post"> <article> <div id="footer"> <footer>修改文檔類型,從 HTML4 doctype:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">修改為 HTML5 doctype:
<!DOCTYPE html>修改編碼信息,從 HTML4:
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">改為 HTML5:
<meta charset="utf-8">所有現(xiàn)代瀏覽器都支持 HTML5 語(yǔ)義元素。
此外,您可以“教授”老式瀏覽器如何處理“未知元素”。
為 Internet Explorer 支持而添加的 shiv:
<!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->注釋:請(qǐng)?jiān)?HTML5 瀏覽器支持中閱讀更多有關(guān) shiv 的知識(shí)。
請(qǐng)看已有的 CSS 樣式:
div#header,div#footer,div#content,div#post { border:1px solid grey;margin:5px;margin-bottom:15px;padding:8px;background-color:white;}div#header,div#footer { color:white;background-color:#444;margin-bottom:5px;}div#content { background-color:#ddd;}div#menu ul { margin:0;padding:0;}div#menu ul li { display:inline; margin:5px;}Duplicate with equal CSS styles for HTML5 semantic elements:header,footer,section,article { border:1px solid grey;margin:5px;margin-bottom:15px;padding:8px;background-color:white;}header,footer { color:white;background-color:#444;margin-bottom:5px;}section { background-color:#ddd;}nav ul { margin:0;padding:0;}nav ul li { display:inline; margin:5px;}把 id="header" 和 id="footer" 的 <div> 元素:
<div id="header"> <h1>Monday Times</h1></div>...<div id="footer"> <p>© 2014 W3Schools. All rights reserved.</p></div>修改為 HTML5 語(yǔ)義元素 <header> 和 <footer>:
<header> <h1>Monday Times</h1></header>...<footer> <p>© 2014 W3Schools. All rights reserved.</p></footer>把 id="menu" 的 <div> 元素:
<div id="menu"> <ul> <li>News</li> <li>Sports</a></li> <li>Weather</li> </ul></div>修改為 HTML5 語(yǔ)義元素 <nav>:
<nav> <ul> <li>News</li> <li>Sports</a></li> <li>Weather</li> </ul></nav>把 id="content" 的 the <div> 元素:
<div id="content">...</div>修改為 HTML5 語(yǔ)義元素 <section>:
<section>...</section>把 class="post" 的所有 <div> 元素:
<div class="post"> <h2>News Article</h2> <p>Ipsum lurum hurum turum ipsum lurum hurum turum ipsum lurum hurum turum ipsum lurum hurum turum.</p></div>修改為 HTML5 語(yǔ)義元素 <article>:
<article> <h2>News Article</h2> <p>Ipsum lurum hurum turum ipsum lurum hurum turum ipsum lurum hurum turum ipsum lurum hurum turum.</p></article>刪除這些“不再需要的”樣式:
div#header,div#footer,div#content,div#post { border:1px solid grey;margin:5px;margin-bottom:15px;padding:8px;background-color:white;}div#header,div#footer { color:white;background-color:#444;margin-bottom:5px;}div#content { background-color:#ddd;}div#menu ul { margin:0;padding:0;}div#menu ul li { display:inline; margin:5px;}最后您可以刪除 <head> 標(biāo)簽。HTML5 中不再需要它們:
實(shí)例 <!DOCTYPE html><html lang="en"><title>HTML5</title><meta charset="utf-8"><!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]--><style>body { font-family:Verdana,sans-serif;font-size:0.8em;}header,footer,section,article { border:1px solid grey; margin:5px;margin-bottom:15px;padding:8px; background-color:white;}header,footer { color:white;background-color:#444;margin-bottom:5px;}section { background-color:#ddd;}nav ul { margin:0;padding:0;}nav ul li { display:inline; margin:5px;}</style><body><header> <h1>Monday Times</h1></header><nav> <ul> <li>News</li> <li>Sports</li> <li>Weather</li> </ul></nav><section><h2>News Section</h2><div id="post"> <h2>News Article</h2> <p>Ipsum lurum hurum turum ipsum lurum hurum turum ipsum lurum hurum turum ipsum lurum hurum turum.</p> <p>Ipsum lurum hurum turum ipsum lurum hurum turum ipsum lurum hurum turum ipsum lurum hurum turum.</p> <p>Ipsum lurum hurum turum ipsum lurum hurum turum ipsum lurum hurum turum ipsum lurum hurum turum.</p></div><div id="post"><h2>News Article</h2> <p>Ipsum lurum hurum turum ipsum lurum hurum turum ipsum lurum hurum turum ipsum lurum hurum turum.</p> <p>Ipsum lurum hurum turum ipsum lurum hurum turum ipsum lurum hurum turum ipsum lurum hurum turum.</p> <p>Ipsum lurum hurum turum ipsum lurum hurum turum ipsum lurum hurum turum ipsum lurum hurum turum.</p></div></section><footer> <p>© 2014 Monday Times. All rights reserved.</p></footer></body></html>在 HTML5 標(biāo)準(zhǔn)中,<article> <section> 與 <div> 之間的差異很小,令人困惑。
在 HTML5 標(biāo)準(zhǔn)中,<section> 元素被定位為相關(guān)元素的塊。
<article> 元素被定義為相關(guān)元素的完整的自包含塊。
<div> 元素被定義為子元素的塊。
如何理解呢?
在上面的例子中,我們?cè)褂?<section> 作為相關(guān) <articles> 的容器。
但是,我們也能夠把 <article> 用作文章的容器。
下面是一些不同的例子:
<article> 中的 <article>:<article><h2>Famous Cities</h2><article><h2>London</h2><p>London is the capital city of England. It is the most populous city in the United Kingdom,with a metropolitan area of over 13 million inhabitants.</p></article><article><h2>Paris</h2><p>Paris is the capital and most populous city of France.</p></article><article><h2>Tokyo</h2><p>Tokyo is the capital of Japan, the center of the Greater Tokyo Area,and the most populous metropolitan area in the world.</p></article></article> <article> 中的 <div>:<article><h2>Famous Cities</h2><div class="city"><h2>London</h2><p>London is the capital city of England. It is the most populous city in the United Kingdom,with a metropolitan area of over 13 million inhabitants.</p></div><div class="city"><h2>Paris</h2><p>Paris is the capital and most populous city of France.</p></div><div class="city"><h2>Tokyo</h2><p>Tokyo is the capital of Japan, the center of the Greater Tokyo Area,and the most populous metropolitan area in the world.</p></div></article> <article> 中的 <section> 中的 <div>:<article><section><h2>Famous Cities</h2><div class="city"><h2>London</h2><p>London is the capital city of England. It is the most populous city in the United Kingdom,with a metropolitan area of over 13 million inhabitants.</p></div><div class="city"><h2>Paris</h2><p>Paris is the capital and most populous city of France.</p></div><div class="city"><h2>Tokyo</h2><p>Tokyo is the capital of Japan, the center of the Greater Tokyo Area,and the most populous metropolitan area in the world.</p></div></section><section><h2>Famous Countries</h2><div class="country"><h2>England</h2><p>London is the capital city of England. It is the most populous city in the United Kingdom,with a metropolitan area of over 13 million inhabitants.</p></div><div class="country"><h2>France</h2><p>Paris is the capital and most populous city of France.</p></div><div class="country"><h2>Japan</h2><p>Tokyo is the capital of Japan, the center of the Greater Tokyo Area,and the most populous metropolitan area in the world.</p></div></section></article>
當(dāng)前名稱:HTML5遷移-4.5HTML5
當(dāng)前URL:http://m.rwnh.cn/article1/dghhdod.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站排名、品牌網(wǎng)站設(shè)計(jì)、企業(yè)網(wǎng)站制作、網(wǎng)站建設(shè)、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
網(wǎng)頁(yè)設(shè)計(jì)公司知識(shí)