search
HomeWeb Front-endH5 Tutorial细谈HTML 5新增的元素

对于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>


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>

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

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

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

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

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

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

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

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

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

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

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

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

交互性

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

details

datagrid

menu

command

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

一句话记录生活中的点点滴滴,a5e9d42b316b6d06c62de0deffc36939   e911751791aa3ba95dc724e2fb905976更多a814477f903c8e27bd1ff8e5c6bbe7c1   e388a4556c0f65e1904146cc1a846bee交流与分享,拉近你和朋友,支持 MSN/GTalk/QQ、短信、手机 WAP94b3e26ee717c64999d7867364b1b4a3 857b9e4d92e41388578e3abed1e3bdfb它可以有一个open的特性,用来显示细节与否。

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

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


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


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

Statement
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
H5: The Future of Web Content and DesignH5: The Future of Web Content and DesignMay 01, 2025 am 12:12 AM

H5 (HTML5) will improve web content and design through new elements and APIs. 1) H5 enhances semantic tagging and multimedia support. 2) It introduces Canvas and SVG, enriching web design. 3) H5 works by extending HTML functionality through new tags and APIs. 4) Basic usage includes creating graphics using it, and advanced usage involves WebStorageAPI. 5) Developers need to pay attention to browser compatibility and performance optimization.

H5: New Features and Capabilities for Web DevelopmentH5: New Features and Capabilities for Web DevelopmentApr 29, 2025 am 12:07 AM

H5 brings a number of new functions and capabilities, greatly improving the interactivity and development efficiency of web pages. 1. Semantic tags such as enhance SEO. 2. Multimedia support simplifies audio and video playback through and tags. 3. Canvas drawing provides dynamic graphics drawing tools. 4. Local storage simplifies data storage through localStorage and sessionStorage. 5. The geolocation API facilitates the development of location-based services.

H5: Key Improvements in HTML5H5: Key Improvements in HTML5Apr 28, 2025 am 12:26 AM

HTML5 brings five key improvements: 1. Semantic tags improve code clarity and SEO effects; 2. Multimedia support simplifies video and audio embedding; 3. Form enhancement simplifies verification; 4. Offline and local storage improves user experience; 5. Canvas and graphics functions enhance the visualization of web pages.

HTML5: The Standard and its Impact on Web DevelopmentHTML5: The Standard and its Impact on Web DevelopmentApr 27, 2025 am 12:12 AM

The core features of HTML5 include semantic tags, multimedia support, offline storage and local storage, and form enhancement. 1. Semantic tags such as, etc. to improve code readability and SEO effect. 2. Simplify multimedia embedding with labels. 3. Offline storage and local storage such as ApplicationCache and LocalStorage support network-free operation and data storage. 4. Form enhancement introduces new input types and verification properties to simplify processing and verification.

H5 Code Examples: Practical Applications and TutorialsH5 Code Examples: Practical Applications and TutorialsApr 25, 2025 am 12:10 AM

H5 provides a variety of new features and functions, greatly enhancing the capabilities of front-end development. 1. Multimedia support: embed media through and elements, no plug-ins are required. 2. Canvas: Use elements to dynamically render 2D graphics and animations. 3. Local storage: implement persistent data storage through localStorage and sessionStorage to improve user experience.

The Connection Between H5 and HTML5: Similarities and DifferencesThe Connection Between H5 and HTML5: Similarities and DifferencesApr 24, 2025 am 12:01 AM

H5 and HTML5 are different concepts: HTML5 is a version of HTML, containing new elements and APIs; H5 is a mobile application development framework based on HTML5. HTML5 parses and renders code through the browser, while H5 applications need to run containers and interact with native code through JavaScript.

The Building Blocks of H5 Code: Key Elements and Their PurposeThe Building Blocks of H5 Code: Key Elements and Their PurposeApr 23, 2025 am 12:09 AM

Key elements of HTML5 include,,,,,, etc., which are used to build modern web pages. 1. Define the head content, 2. Used to navigate the link, 3. Represent the content of independent articles, 4. Organize the page content, 5. Display the sidebar content, 6. Define the footer, these elements enhance the structure and functionality of the web page.

HTML5 and H5: Understanding the Common UsageHTML5 and H5: Understanding the Common UsageApr 22, 2025 am 12:01 AM

There is no difference between HTML5 and H5, which is the abbreviation of HTML5. 1.HTML5 is the fifth version of HTML, which enhances the multimedia and interactive functions of web pages. 2.H5 is often used to refer to HTML5-based mobile web pages or applications, and is suitable for various mobile devices.

See all articles

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

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft