HTML5瀏覽器支持-4.2HTML5

您可以幫助老版本瀏覽器處理 HTML5。

創(chuàng)新互聯(lián)建站網(wǎng)站建設(shè)公司,提供成都做網(wǎng)站、網(wǎng)站制作、成都外貿(mào)網(wǎng)站建設(shè),網(wǎng)頁設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);可快速的進(jìn)行網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,是專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!

HTML5 瀏覽器支持

所有現(xiàn)代瀏覽器都支持 HTML5。

此外,所有瀏覽器,不論新舊,都會自動把未識別元素當(dāng)做行內(nèi)元素來處理。

正因如此,您可以幫助老式瀏覽器處理”未知的“ HTML 元素。

注釋:您甚至可以教授石器時(shí)代的 IE6 如何處理未知的 HTML 元素。

把 HTML5 元素定義為塊級元素

HTML5 定義了八個新的語義 HTML 元素。所有都是塊級元素。

您可以把 CSS display 屬性設(shè)置為 block,以確保老式瀏覽器中正確的行為:

實(shí)例 header, section, footer, aside, nav, main, article, figure { display: block; }
向 HTML 添加新元素

您可以通過瀏覽器 trick 向 HTML 添加任何新元素:

本例向 HTML 添加了一個名為 <myHero> 的新元素,并為其定義 display 樣式:

實(shí)例 <!DOCTYPE html><html><head> <title>Creating an HTML Element</title> <script>document.createElement("myHero")</script> <style> myHero { display: block; background-color: #ddd; padding: 50px; font-size: 30px; } </style> </head><body><h1>My First Heading</h1><p>My first paragraph.</p><myHero>My First Hero</myHero></body></html>

已添加的 JavaScript 語句 document.createElement("myHero"),僅適用于 IE。

Internet Explorer 的問題

上述方案可用于所有新的 HTML5 元素,但是:

注意:Internet Explorer 8 以及更早的版本,不允許對未知元素添加樣式。

幸運(yùn)的是,Sjoerd Visscher 創(chuàng)造了 "HTML5 Enabling JavaScript", "the shiv":

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

以上代碼是一段注釋,但是 IE9 的早期版本會讀取它(并理解它)。

完整的 Shiv 解決方案 實(shí)例 <!DOCTYPE html><html><head> <title>Styling HTML5</title> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--></head><body><h1>My First Article</h1><article>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.</article></body></html>

引用 shiv 代碼的鏈接必須位于 <head> 元素中,因?yàn)?Internet Explorer 需要在讀取之前認(rèn)識所有新元素。

HTML5 Skeleton 實(shí)例 <!DOCTYPE html><html lang="en"><head><title>HTML5 Skeleton</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,nav, section,article,footer{border:1px solid grey; margin:5px; padding:8px;}nav ul {margin:0; padding:0;}nav ul li {display:inline; margin:5px;}</style></head><body><header> <h1>HTML5 SKeleton</h1></header><nav><ul> <li><a href="html5_semantic_elements.asp">HTML5 Semantic</a></li> <li><a href="html5_geolocation.asp">HTML5 Geolocation</a></li> <li><a href="html5_canvas.asp">HTML5 Graphics</a></li></ul></nav><section><h1>Famous Cities</h1><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></section><footer><p>© 2014 W3Schools. All rights reserved.</p></footer></body></html>

本文標(biāo)題:HTML5瀏覽器支持-4.2HTML5
當(dāng)前路徑:http://www.bm7419.com/article4/dghhdoe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、微信小程序、企業(yè)建站、網(wǎng)站內(nèi)鏈、關(guān)鍵詞優(yōu)化網(wǎng)站排名

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化