HTML5 瀏覽器支持(怎麼樣讓低版本瀏覽器支持html5?)

你可讓一些較早的瀏覽器(不支持HTML5)支持 HTML5。html

現代的瀏覽器都支持 HTML5。html5

此外,全部瀏覽器,包括舊的和最新的,對沒法識別的元素會做爲內聯元素自動處理。api

正由於如此,你能夠 "教會" 瀏覽器處理 "未知" 的 HTML 元素。(也就是html5的新元素)瀏覽器

HTML5 定了 8 個新的 HTML 語義(semantic) 元素。全部這些元素都是 塊級 元素。app

爲了能讓舊版本的瀏覽器正確顯示這些元素,你能夠設置 CSS 的 display 屬性值爲 block:dom

實例

header, section, footer, aside, nav, main, article, figure {
    display: block; 
}
 
Internet Explorer 8 及更早 IE 版本的瀏覽器不支持以上的方式。
<!--[if lt IE 9]>
  <script src="http://apps.bdimg.com/libs/html5shiv/3.7/html5shiv.min.js"></script>
<![endif]-->
以上代碼是一個註釋,做用是在 IE 瀏覽器的版本小於 IE9 時將讀取 html5.js 文件,並解析它。
 
<!DOCTYPE html>
<html>

<head>
  <title>Styling HTML5</title>
  <!--[if lt IE 9]>
  <script src="http://apps.bdimg.com/libs/html5shiv/3.7/html5shiv.min.js"></script>
  <![endif]-->
</head>

<body>

<h1>個人第一篇文章</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>
 
html5shiv.js 引用代碼必須放在 <head> 元素中,由於 IE 瀏覽器在解析 HTML5 新元素時須要先加載該文件。
相關文章
相關標籤/搜索