嶄新新的頁面佈局javascript
傳統的:css
HTML5:html
儘管使用<!DOCTYPE html>
,即便瀏覽器不懂這句話也會按照標準模式去渲染前端
用<figure>
和<figcaption>
來語義化地表示帶標題的圖片html5
<figure> <img src="path/to/image" alt="About image" /> <figcaption> <p>This is an image of something interesting. </p> </figcaption> </figure>
<small>
<small>
已經被從新定義了,如今被用來表示小的排版,如網站底部的版權聲明java
HTML5沒有嚴格的要求屬性必須加引號,閉合不閉合,可是建議加上引號和閉合標籤正則表達式
若是咱們給Input的type設置爲email,瀏覽器就會驗證這個輸入是不是email類型,固然不能只依賴前端的校驗,後端也得有相應的校驗後端
這個input屬性的意義就是沒必要經過javascript來作placeholder的效果了瀏覽器
使用Local Storage能夠永久存儲大的數據片斷在客戶端(除非主動刪除),目前大部分瀏覽器已經支持,在使用以前能夠檢測一下window.localStorage是否存在ide
默認的,HTML5新元素被以inline的方式渲染,不過能夠經過下面這種方式讓其以block方式渲染
header, footer, article, section, nav, menu, hgroup { display: block; }
不幸的是IE會忽略這些樣式,能夠像下面這樣fix:
document.createElement("article"); document.createElement("footer"); document.createElement("header"); document.createElement("hgroup"); document.createElement("nav"); document.createElement("menu");
通常在header裏面用來將一組標題組合在一塊兒,如
<header> <hgroup> <h1> Recall Fan Page </h1> <h2> Only for people who want the memory of a lifetime. </h2> </hgroup> </header>
required屬性定義了一個input是不是必須的,你能夠像下面這樣聲明
<input type="text" name="someInput" required>
或者
<input type="text" name="someInput" required="required">
正如它的詞義,就是聚焦到輸入框裏面
<input type="text" name="someInput" placeholder="Douglas Quaid" required autofocus>
HTML5提供了<audio>
標籤,你不須要再按照第三方插件來渲染音頻,大多數現代瀏覽器提供了對於HTML5 Audio的支持,不過目前仍舊須要提供一些兼容處理,如
<audio autoplay="autoplay" controls="controls"> <source src="file.ogg" /><!--FF--> <source src="file.mp3" /><!--Webkit--> <a href="file.mp3">Download this file.</a> </audio>
和Audio很像,<video>
標籤提供了對於video的支持,因爲HTML5文檔並無給video指定一個特定的編碼,因此瀏覽器去決定要支持哪些編碼,致使了不少不一致。Safari和IE支持H.264編碼的格式,Firefox和Opera支持Theora和Vorbis編碼的格式,當使用HTML5 video的時候,你必須都提供:
<video controls preload> <source src="cohagenPhoneCall.ogv" type="video/ogg; codecs='vorbis, theora'" /> <source src="cohagenPhoneCall.mp4" type="video/mp4; 'codecs='avc1.42E01E, mp4a.40.2'" /> <p> Your browser is old. <a href="cohagenPhoneCall.mp4">Download this video instead.</a> </p> </video>
preload屬性就像它的字面意思那麼簡單,你須要決定是否須要在頁面加載的時候去預加載視頻
<video preload>
<video preload controls>
因爲pattern屬性,咱們能夠在你的markup裏面直接使用正則表達式了
<form action="" method="post"> <label for="username">Create a Username: </label> <input type="text" name="username" id="username" placeholder="4 <> 10" pattern="[A-Za-z]{4,10}" autofocus required> <button type="submit">Go </button> </form>
除了Modernizr以外咱們還能夠經過javascript簡單地檢測一些屬性是否支持,如:
<script> if (!'pattern' in document.createElement('input') ) { // do client/server side validation } </script>
把<mark>
元素看作是高亮的做用,當我選擇一段文字的時候,javascript對於HTML的markup效果應該是這樣的:
<h3> Search Results </h3> <p> They were interrupted, just after Quato said, <mark>"Open your Mind"</mark>. </p>
<div>
HTML5已經引入了這麼多元素,那麼div咱們還要用嗎?div你能夠在沒有更好的元素的時候去用。
不要等2022了,如今就可使用了,just do it.
<div id="myDiv" data-custom-attr="My Value"> Bla Bla </div>
CSS中使用:
<style> h1:hover:after { content: attr(data-hover-response); color: black; position: absolute; left: 0; } </style>
<h1 data-hover-response="I Said Don’t Touch Me!"> Don’t Touch Me </h1>
<output>
元素用來顯示計算結果,也有一個和label同樣的for屬性
HTML5引用的range類型能夠建立滑塊,它接受min, max, step和value屬性 可使用css的:before和:after來顯示min和max的值
<input type="range" name="range" min="0" max="10" step="1" value=""> input[type=range]:before { content: attr(min); padding-right: 5px; } input[type=range]:after { content: attr(max); padding-left: 5px; }
原文來自:http://justjavac.com/html5/2012/04/05/25-html5-features-tips-and-techniques-you-must-know.html