Home > Web Front-end > H5 Tutorial > body text

Code sharing for the main new tags in HTML5

黄舟
Release: 2017-03-30 13:12:25
Original
2494 people have browsed it

HTML5Introduction

HTML5 is The next generation of HTML standard specification after HTML4, it provides some new elements and attributes. New tags are beneficial to search engines and semantic analysis, while better helping small screens. In addition, it also provides some new functions. In summary, it has the following major features:

1. Some outdated elements and elements in HTML4 have been cancelled. Attribute tags

These include purely display tags, such as and

, which have been replaced by CSS. HTML5 incorporates some suggestions from XHTML2, including some to improve documentation. Structural functions, such as the use of new HTML tags header, footer, dialog, aside, figure, etc., will allow content creators to create documents more semantically. Previous developers generally used p # when implementing these functions.

##2. Separation of content and presentation

The b and i tags are still retained, but their meanings are different from before. The meaning of these tags is to identify a piece of text. , instead of setting bold or italic styles, the tags u, font, center, and strike have been completely removed.

3, Add some new forms. Input objects include date, URL,

Email

address, other objects have added support for non-Latin characters. HTML5 also introduces microdata, a method of annotating content with machine-readable tags, making it easier to work with the Semantic Web. Overall, these structural improvements allow content creators to create cleaner, more efficient content. Web pages that are easy to manage are more friendly to search engines and screen reading software. 4. New and more reasonable tags. ##Multiple Media objects will no longer be bound in object or embedTag, but the video will have the video tag and the audio will have the audio tag

5. Local. Storage

Added browser-side storage functions such as localStorage/sessionStorage/indexedDB

6. Canvas object

will be provided to the browser. Brings the ability to draw graphics directly and operate graphics directly in the browser

7. New

API

extension

for HTMLDocument and The HTMLElement interface provides new API extensions.

8. New syntax (1) DOCTYPE

The HTML syntax of HTML5 requires that the document must declare DOCTYPE to ensure that the browser can operate in standards mode Display page. The declaration method is:

<!DOCTYPE html>
Copy after login

It is not case sensitive.

(2) Charset

In the HTML syntax of HTML5, there are three forms to declare the encoding type of

string

:

At the transport level, set Content-Type in the header of the HTTP instance.

At the beginning of the file, set a Unicode Bype Order Mark (BOM). This character provides a signature for the encoding method of the file.

  • In the content between the first 1024 bytes of the document, use the meta element with the charset attribute to declare the encoding method. For example: .

  • (3) MathML and SVG

    HTML5’s HTML syntax allows the use of MathML (Mathematical Markup Language) and SVG (Scalable
  • Vector Graphics
  • )element. For example, a very simple HTML page contains a circle drawn by an svg element:

    <!doctype html><title>SVG in text/html</title><p>
     A green circle: <svg> <circle r="50" cx="50" cy="50" fill="green"/> </svg></p>
    Copy after login

  • section

#section element is the most basic way to divide the page document structure. The main structural element is mainly used to hierarchically divide the content on the pages in the website or application. A section element usually consists of content and its title.

If the content of the element can be displayed together to express the corresponding meaning, it can be defined as an article element, and there is no need to use the section element.

The section element is not a general container element, so if an element needs to define a corresponding style or script, it is recommended to use the p element. The use of section ensures that the content of this element can be clearly displayed in the document. Steel.

like:
<!DOCTYPE Html><html><head>
    <title>Graduation Ceremony Summer 2022</title></head><body>
    <h1>Graduation</h1>
    <section>
        <h1>Ceremony</h1>
        <p>Opening Procession</p>
        <p>Speech by Validactorian</p>
        <p>Speech by Class President</p>
        <p>Presentation of Diplomas</p>
        <p>Closing Speech by Headmaster</p>
    </section>
    <section>
        <h1>Graduates</h1>
        <ul>
            <li>Molly Carpenter</li>
            <li>Anastasia Luccio</li>
            <li>Ebenezar McCoy</li>
            <li>Karrin Murphy</li>
            <li>Thomas Raith</li>
            <li>Susan Rodriguez</li>
        </ul>
    </section></body></html>
Copy after login

article

article 元素代表文档、页面或应用程序中的所有“正文”部分,它所描述的内容应该是独立的、完整的、可以独自被外部引用的,可以是一篇博客、一篇报刊中的文章、一篇论坛帖子、一段用户评论、一个独立的插件,或任何独立于上下文中其他部分的内容。

article是一个特殊的section标签,它比section具有更明确的语义,它代表一个独立的、完整的相关内容块。一般来说,article会有标题部分。

当article内嵌article时,原则上来说,内部的article的内容是和外层的article内容相关的。例如,一篇博客中,包含用户提交的评论的article应该嵌套在包含博客文章article中。

<article>
    <h1>Safari 5 released</h1>
    <p>7 Jun 2010. Just after the announcement of the new iPhone 4 at WWDC.</p>
    <p>Apple announced the release of Safari 5 for Windows and Mac......</p></article>
Copy after login

nav

nav 元素是一个可以作为页面导航的链接组,其中的导航元素链接到其他页面或当前页面的其他部分。一个页面可以拥有多个nav元素,作为页面整体不同部分的导航。在nav元素中,一般以ul列表的形式来具体放置该组链接元素。

下面是w3c给出的一个示例代码:

<body>
    <h1>The Wiki Center Of Exampland</h1>
    <nav>
        <ul>
            <li><a href="/">Home</a></li>
            <li><a href="/events">Current Events</a></li>
            ...more...        </ul>
    </nav>
    <article>
        <header>
            <h1> Demos in Exampland</h1>
            <p>Written by A. N. Other.</p>
        </header>
        <nav>
            <ul>
                <li><a href="#public">Public demonstrations</a></li>
                <li><a href="#destroy">Demolitions</a></li>
                ...more...            </ul>
        </nav>
        <p>
            <section id="public">
                <h1>Public demonstrations</h1>
                <p> ...more...</p>
            </section>
            <section id="destroy">
                <h1>Demolitions</h1>
                <p>...more...</p>
            </section>
            ...more...        </p>
        <footer>
            <p><a href="?edit">Edit</a> | <a href="?delete">Delete</a> | <a href="?Rename">Rename</a></p>
        </footer>
    </article>
    <footer>
        <p><small>© copyright 1998 Exampland Emperor</small></p>
    </footer></body>
Copy after login

aside

aside元素用来表示当前页面或文章的附属信息部分,它可以包含与当前页面或主要内容相关的引用、侧边栏、广告、导航条、以及其他有别于主要内容的部分。

根据目前的规范,aside元素有两种使用方法:

  • 被包含在article中作为主要内容的附属信息部分,其中的内容可以是当前文章有关的引用,词汇列表等。

  • 在article外使用,作为页面或站点全局的附属信息部分;最典型的形式是侧边栏,其中的内容可以是友情链接、附属导航或广告单元等。

下面的代码示例综合了以上两种方法:

<body>
    <header>
        <h1>My Blog</h1>
    </header>
    <article>
        <h1>My Blog Post</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
            incididunt ut labore et dolore magna aliqua.</p>
        <aside>
            <h1>Glossary</h1>
            <dl>
                <dt>Lorem</dt>
                <dd>ipsum dolor sit amet</dd>
            </dl>
        </aside>
    </article>
    <aside>
        <h2>Blogroll</h2>
        <ul>
            <li><a href="#">My Friend</a></li>
            <li><a href="#">My Other Friend</a></li>
            <li><a href="#">My Best Friend</a></li>
        </ul>
    </aside></body>
Copy after login

hgroup

hgroup 元素是将标题及其子标题进行分组的元素。hgroup元素通常对h1~h6元素进行分组,如将一个内容区块的标题及其子标题划为一组:

<hgroup>
  <h1>Welcome to my WWF</h1>
  <h2>For a living planet</h2></hgroup><p>The rest of the content...</p>
Copy after login

header

header 元素是一种具有引导作用和导航作用的结构元素,通常用来放置整个页面或页面内的一个article元素或section元素的标题,也可以包含其他内容,例如数据表格、搜索表单或相关的logo图片

我们可以使用该标签来显示整个网页的标题部分:

<header>
    <h1>The most important heading on this page</h1></header>
Copy after login

同一个页面内,每一个内容区块都可以有自己的header元素,例如:

<header> 
  <h1>The most important heading on this page</h1></header><article> 
  <header>   
    <h1>Title of this article</h1> 
  </header> 
  <p>...Lorem Ipsum dolor set amet...</p></article>
Copy after login

footer

footer 元素可以作为其上层父级内容区块或一个根区块的脚注。footer 元素通常包括其相关区块的脚注信息,如作者、相关阅读链接以及版权信息等。

过去(及目前),我们通常使用类似下面这样的代码来写页面的页脚:

<p id="footer">
  <ul>
     <li>copyright</li>
     <li>sitemap</li>
     <li>contact</li>
     <li>to top</li>
  </ul><p>
Copy after login

在HTML5中,我们可以不使用p,而用更加语义化的footer来写:

<footer>
  <ul>
     <li>copyright</li>
     <li>sitemap</li>
     <li>contact</li>
     <li>to top</li>
  </ul></footer>
Copy after login

在同一个页面中可以使用多个footer元素,即可以用作页面整体页脚,也可以作为一个内容区块的结尾,例如,我们可以将footer直接写在section或是article中:

<section>
   Section content appears here.   <footer>
      Footer information for section.   </footer></section><article>
   Article content appears here.   <footer>
      Footer information for article.   </footer></article>
Copy after login

address

address元素用来在文档中呈现联系信息,包括文档创建者的名字、站点链接、电子邮箱、真实地址、电话号码等;address不只是用来呈现电子邮箱或真实地址这样的“地址”概念,而应该包括与文档创建人相关的各类联系方式信息。

根据以上定义,我们可以使用下面的代码来展示一些志愿者的名字及主页链接:

The HTML5 Doctor is run by the following group of volunteers:<address>
  <a href="http://html5doctor.com/author/jacko">Jack Osborne</a>,  
  <a href="http://html5doctor.com/author/richc">Rich Clark</a>,  
  <a href="http://html5doctor.com/author/miker">Mike Robinson</a>,
  </address>
Copy after login

下面是另一个范例:

<footer>
  <p class="vcard"> by    <address class="author">
      <em class="fn"><a title="Posts by Jack Osborne" href="#">Jack Osborne</a></em>
    </address> on    <time datetime="2009-11-04" class="published updated">November 4th, 2009</time>
  </p></footer>
Copy after login

video

通过

过去(及目前),我们通常要使用类似下面这样繁冗丑陋的代码来将视频放置在页面中,但这种方式要求浏览器安装有Flash插件,并支持JavaScript

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" 
height="344"codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0">
  <param name="allowFullScreen" value="true" />
  <param name="allowscriptaccess" value="always" />
  <param name="src" value="http://www.youtube.com/v/oHg5SJYRHA0&hl=en&fs=1&" />
  <param name="allowfullscreen" value="true" />
  <embed type="application/x-shockwave-flash" width="425" height="344"
  src="http://www.youtube.com/v/oHg5SJYRHA0&hl=en&fs=1&" allowscriptaccess="always" allowfullscreen="true">
  </embed></object>
Copy after login

HTML5的方式:

<video width="640"  height="360" src="http://www.youtube.com/demo/google_main.mp4"  controls autobuffer>
  <p>
    Try this page in Safari  4! Or you can    
    <a  href="http://www.youtube.com/demo/google_main.mp4">download the  video</a>
    instead.  </p></video>
Copy after login

  • Autoplay: 用来设定视频是否在页面加载后自动播放。

  • Src: 为视频指定文件链接或下载路径,当浏览器不支持

  • Autobuffer: 用来设定视频是否自动缓冲;如果设定,那么页面加载之后,视频会自动下载缓冲,当用户点击播放按钮后,至少已经有一部分视频可以直接观看而无需等待了。

  • Poster: 用来为视频设置一个“相框默认图片”性质的背景图片;当视频无法正常加载播放时可以向用户呈现。

  • Controls: 用来设置是否为视频添加控制条,例如“播放”、“暂停”等;控制条的外观可以自定义。

  • Loop: 用来设置视频是否循环播放。

  • Width , Height: 用来控制视频的宽度与高度。

audio

HTML5中的新元素标签

  • src:音频文件路径。

  • autobuffer:设置是否在页面加载时自动缓冲音频。

  • autoplay:设置音频是否自动播放。

  • loop:设置音频是否要循环播放。

  • controls:设置是否显示播放控制面板。

可以看到这些属性和

<audio src="elvis.ogg" controls autobuffer></audio>
Copy after login

根据定义规范,以下几种API方法是可以使用的:

  • play():播放音频

  • pause():暂停播放

  • canPlayType():命令浏览器判断当前音频文件是否可以被播放

  • buffered():设定文件需要缓冲部分的开始与结束时间点。

另外,我们可以使用元素标签来配合

<audio controls autobuffer>
  <source src="elvis.ogg" />
  <source src="elvis.mp3" />
  <!-- now include flash fall back --></audio>
Copy after login

datalist

datalist 与 input 的新属性list一起使用可以创建组合框,双击input的时候可以提供选项让用户选择,类似历史记录一样。

<input list="browsers"><datalist id="browsers">
 <option value="Safari">
 <option value="Internet Explorer">
 <option value="Opera">
 <option value="Firefox"></datalist>
Copy after login

The above is the detailed content of Code sharing for the main new tags in HTML5. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!