Home Web Front-end H5 Tutorial 细谈HTML 5新增的元素

细谈HTML 5新增的元素

May 17, 2016 am 09:09 AM

对于HTML的渲染,浏览器一直停留在1999年的水平。为此,HTML 5是一个实用主义方案,这样不仅可以继续处理这么多年来散落在世界各个角落的HTML,也可以让浏览器厂商更容易添加新特性。这就叫degrade gracefully(优雅降级)。让我们来看看HTML 5增加的一些新元素。

HTML 5结构元素

这真是大快人心。目前,我们定义结构只能通过一个“万能”的p, 试图通过设置它的特性id的值如header, footer, sidebar等来分别表达头部,底部或者侧栏等。有了它们,代码编写者不再需要为id的命名费尽心思,对于手机、阅读器等设备更有语义的好处。HTML 5增加了新的结构元素来表达这些最常用的结构:

◆section: 这可以表达书本的一部分或一章,或者一章内的一节

◆header: 页面主体上的头部。并非head元素

◆footer: 页面的底部(页脚),可以是一封邮件签名的所在

◆nav: 到其他页面的链接集合

◆article: 诸如blog, 杂志,纲要等之中的一条独立记录。

举个例子,一个blog的首页,用HTML 5写的话,可以是这样(有省略):

<<!DOCTYPE HTML> <HTML>   <head>     <title>realazy</title>   </head> 
<body> 
<header> 
     <h1>Realazy</h1></header> 
<section>       
<article>       
<h2><a href="http://realazy.org/blog" mce_href="http://realazy.org/blog">标题</a></h2> 
 <p>内容在此...(省略n字)</p>     
 </article>     <article>     
 <h2><a href="http://realazy.org/blog" mce_href="http://realazy.org/blog">标题2</a></h2>     
 <p>内容2在此...(省略n字)</p>    
  </article>     ...     </section>   
<footer> nav>     <ul>   
  <li><a href="http://realazy/blog" mce_href="http://realazy/blog">导航1</a></li>       
  <li><a href="http://realazy/blog" mce_href="http://realazy/blog">导航2</a></li>       ...     
  </ul>    
   </nav> 
  <p>© 2007 realazy</p>     
  </footer>   
  </body>
   </HTML>
Copy after login


HTML还增加以下三个块级元素:

◆aside

◆figure/code>

◆dialog

aside可以用以表达注记、贴士、侧栏、摘要、插入的引用等诸如作为补充主体的内容。比如这样表达blog的侧栏:

<aside>   
<h3>最新文章</h3>   
<ul> 
  <li><a href="http://realazy.org/blog/" mce_href="http://realazy.org/blog/">文章标题</a></li>     ...   
  </ul> 
  </aside>
Copy after login

figure元素表示一个有说明的块级图片。比如:

dialog元素用于表达人们之间的对话。在HTML 5中,dt用于表示说话者,而dd则用来表示说话者的内容。如:

<dialog>   
<dt>佛</dt>   
<dd>色即是空</dd>   
<dt>悟空</dt>   
<dd>
Copy after login

我现在需要点空……行内(inline)的语义元素,m元素用来标记一些不是那么需要着重强调的文本。现在尚有争议,可能最终会改为mark.time元素如其名,用来表达时间。它需要一个datetime的特性来标明机器能够认识的时间,如:

<time datetime="2008-08-08T20:08:08">2008年8月8日晚上8时8分8秒</tiem>
Copy after login

meter元素表达特定范围内的数值。可用于薪水、百分比、分数等。比如:

很遗憾地告诉你,我只有150cm它还有6个特性来表达各方面的含义,比如:

<p>您的分数是:<meter value="88.7" min="0" max="100" low="65" high="96" optimum="100">B+</meter>.</p>
Copy after login

还有一个progress,也是义如其名,用以表达进度:

目标完成度:40%嵌入多媒体

新增video和audio元素。顾名思义,分别是用来插入视频和声音的。至于格式,交由浏览器实现,HTML再也不需要特别的代码去播放特定的格式。就像img一样,不管是png, jpg还是gif都可以显示。值得注意的是,它们可以包含内容。比如,可以把歌词放到某段歌曲中去:

<audio src="谁人伴你睡.mp3" mce_src="谁人伴你睡.mp3">   
<p>泪枯干</p>   
<p>难忍怎么委屈自已</p>   
<p>曾经有一刻悲与喜</p>  
 ... 
 </audio>
Copy after login

交互性

HTML 5同时也叫Web Applications 1.0, 因此也进一步发展交互能力。这些标签就是为提高页面的交互体验而生:

details

datagrid

menu

command

details用来表示一段具体的内容,但是内容默认可能不显示,通过某种手段(如点击)与legend交互才显示出来。这跟现在各种通过JavaScript隐藏一段内容,在点击后才显示出来的做法有些类似。比如:

一句话记录生活中的点点滴滴,

   更多  

交流与分享,拉近你和朋友,支持 MSN/GTalk/QQ、短信、手机 WAP

它可以有一个open的特性,用来显示细节与否。

datagrid用来控制数据,可以由用户或者脚本来更新。

menuHTML 2就存在了,不过HTML 4把它废弃了。HTML 5废物利用,并在期内加上command元素。


以上就是细谈HTML 5新增的元素的内容,更多相关内容请关注PHP中文网(www.php.cn)!


本文由HTML5中国网站小编整理转载,使用或转载请注明出处。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles