HTML5特性

1.新的文档类型(New Doctype)

XHTML1.0声明文档类型:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

在HTML5中上面声明将失效,HTML5声明文档类型:

<!DOCTYPE html>

2.script和link无需type属性(No More Types For Scripts and Links)

HTML4XHTML给网页添加CSS和Script文件:

<link rel="stylesheet" href="path/to/stylesheet.css" type="text/css" /> 
<script src="path/to/script.js" type="text/javascript"></script>

HTML5中无需指定type属性:

<link rel="stylesheet" href="path/to/stylesheet.css" /> 
<script src="path/to/script.js"></script>

3.语义Header和Footer(The Semantic Header and Footer)

HTML4XHTML,声明Header和Footer:

<div id="header"></div> 
<div id="footer"></div>

在HTML5中声明:

<header></header> 
<footer></footer>

4.Hgroup

在HTML5中,有许多新引入的元素,hgroup就是其中之一。

假设我的网站名下面紧跟着一个子标题,我可以用<h1>和<h2>标签来分别定义。

然而,这种定义没有说明这两者之间的关系。而且,h2标签的使用会带来更多问题,比如该页面上还有其他标题的时候。

在HTML5中,我们可以用hgroup元素来将它们分组,这样就不会影响文件的大纲。

<header> 
<hgroup> 
  <h1> Recall Fan Page </h1> 
  <h2> Only for people who want the memory of a lifetime. </h2> 
</hgroup> 
</header>

5.标记元素(Mark Element)

你可以把它当做高亮标签。被这个标签修饰的字符串应当和用户当前的行动相关。

比如说,当我在某博客中搜索“Open your Mind时,我可以利用一些JavaScript将出现的词组用<mark>修饰一下。

 

<h3> Search Results </h3> 
<p> They were interrupted, just after Quato said, <mark>"Open your Mind"</mark>. </p>

 

6.图形元素(Figure Element)

在HTML4或XHTML中,下面的这些代码被用来修饰图片的注释:

<img src="path/to/image" alt="About image" /> 
<p>Image of Mars. </p>

然而,上述代码没有将文字和图片内在联系起来。

因此,HTML5引入了<figure>元素,当和<figcaption>结合起来后,我们可以语义化地将注释和相应的图片联系起来。

<figure> 
<img src="path/to/image" alt="About image" /> 
<figcaption> 
  <p>This is an image of something interesting. </p> 
</figcaption> 
</figure>

7.占位符 (Placeholder)

 

<input type="text" placeholder="占位符" />

8.必要属性 (Required Attribute)

HTML5中的新属性“required”指定了某一输入是否必需。有两种方法声明这一属性:

<input type="text" name="someInput" required> 
<input type="text" name="someInput" required="required">

当文本框被指定必需时,如果空白的话表格就不能提交。

9.Autofocus 属性 (Autofocus Attribute)

如果一个特定的输入应该是“选择”或聚焦,默认情况下,我们现在可以利用自动聚焦属性。消除了Javascript的使用。

 

<input type="text" placeholder="Douglas Quaid" required autofocus />

 

10.Audio 支持 (Audio Support)

HTML5的<audio>元素引入解决了依靠第三方插件来渲染音频的问题:

 

<audio autoplay="autoplay" controls="controls"> 
     <source src="file.ogg" /> 
     <source src="file.mp3" /> 
</audio>

兼容性:

firefox支持.ogg音乐文件格式,Webkit浏览器支持.mp3格式,IE不支持,Opera10及以下版本只支持.wav格式。

11.Video 支持 (Video Support)

HTML5中不仅有<audio>元素,而且还有<video>。

然而,和<audio>类似,HTML5中并没有指定视频解码器,它留给了浏览器来决定。

虽然Safari和Internet Explorer9可以支持H.264格式的视频,Firefox和Opera是坚持开源Theora 和Vorbis格式。

因此,指定HTML5的视频时,你必须提供这两种格式:

<video controls preload> 
<source src="file.ogv" type="video/ogg; codecs='vorbis, theora'" /> 
<source src="file.mp4" type="video/mp4; codecs='avc1.42E01E, mp4a.40.2'" /> 
<p> Your browser is old. <a href="file.mp4">Download this video instead.</a> </p> 
</video>

12.正规表达式 (Regular Expressions)

在HTML4或XHTML中,你需要用一些正规表达式来验证特定的文本。

而HTML5中新的pattern属性让我们能够在标签处直接插入一个正规表达式:

<input type="text" pattern="[A-Za-z]{4,10}" />
 
文章摘抄自:http://www.csdn.net/article/2012-02-21/312179
更多详见:http://www.w3school.com.cn/html5/index.asp

 

posted @ 2014-09-05 10:40  苟且偷生脱苦海  阅读(107)  评论(0)    收藏  举报