Code sharing for the main new tags in HTML5

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

HTML5Introduction

HTML5 is The next generation of HTML standard specification after HTML4, it provides some new elements andattributes. New tags are beneficial tosearchengines 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 asand

, 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. Inputobjectsinclude date, URL,

Email

address,otherobjects 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.##MultipleMedia objectswill 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:


          
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:

    SVG in text/html

    A green circle:

    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:
 Graduation Ceremony Summer 2022

Graduation

Ceremony

Opening Procession

Speech by Validactorian

Speech by Class President

Presentation of Diplomas

Closing Speech by Headmaster

Graduates

  • Molly Carpenter
  • Anastasia Luccio
  • Ebenezar McCoy
  • Karrin Murphy
  • Thomas Raith
  • Susan Rodriguez
Copy after login

article

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

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

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

Safari 5 released

7 Jun 2010. Just after the announcement of the new iPhone 4 at WWDC.

Apple announced the release of Safari 5 for Windows and Mac......

Copy after login

nav

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

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

 

The Wiki Center Of Exampland

© copyright 1998 Exampland Emperor

Copy after login

aside

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

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

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

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

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

 

My Blog

My Blog Post

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Copy after login

hgroup

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

Welcome to my WWF

For a living planet

The rest of the content...

Copy after login

header

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

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

The most important heading on this page

Copy after login

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

The most important heading on this page

Title of this article

...Lorem Ipsum dolor set amet...

Copy after login

footer

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

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

  • copyright
  • sitemap
  • contact
  • to top

Copy after login

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

  • copyright
  • sitemap
  • contact
  • to top
Copy after login

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

Section content appears here.
Footer information for section.
Article content appears here.
Footer information for article.
Copy after login

address

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

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

The HTML5 Doctor is run by the following group of volunteers:
Jack Osborne, Rich Clark, Mike Robinson,
Copy after login

下面是另一个范例:

Copy after login

video

通过

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

      
Copy after login

HTML5的方式:

Copy after login

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

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

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

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

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

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

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

audio

HTML5中的新元素标签

  • src:音频文件路径。

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

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

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

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

可以看到这些属性和

Copy after login

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

  • play():播放音频

  • pause():暂停播放

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

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

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

Copy after login

datalist

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

 
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
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!