大家可能都知道HTML5中出现了很多以前没有的标签,例如,header,nav,和footer,在这之前我们如果开发相关的页面布局的时候,往往都是使用CSS来定义相关的头部,导航及其页底部分,如下:
#nav{ padding: 10px... } #header{ padding: 10px ... } #footer{ padding: 10px ... }
定义完之后呢,我们使用p标签来组织页面结构,如下:
<div id=“header”></div> <div id=“nav”></div> <div id=“footer”></div>
这样的代码让我们创建了很多的非样式的CSS定义,是的代码结构复杂并且不直观易懂。
在新的HTML5标准中,我们定义了一系列的标签,帮助你更语义化的定义页面层次和逻辑,你不需要自己定义相关的DIV,HTML5提供了现成的标签来完成上述的结构化定义,如下:
<header></header> <nav></nav> <footer></footer>
使用以上的标签,你只需要在css文件中定义相关的真正的样式信息即可。
在今天的这篇文章中,我们将介绍相关的基本HTML5标签Header,nav和footer。
header标签
在新的标准中header标签定义如下:
“A group of introductory or navigational aids.”
基本意思是“一组介绍性的护着导航相关的辅助内容”。字面上理解header标签不单单只是定义页头内容,也可以定义页头以下其它内容的介绍。这和我们传统的页面header定义并不完全一致。例如:
<header> <h1>HTML5基本标签使用,header,Nav和footer</h1> <div class=”post-meta“> <p>作者信息:gbin1.com</a> <span class=”category“>文章创建类别:HTML5/CSS3</span></p> </div> </header> <article> <p>大家可能都知道HTML5中出现了很多以前没有的标签,例如,header,nav,和footer, 在这之前我们如果开发相关的页面布局的时候,往往都是使用CSS来定义相关的头部,导航及其页底部分</p> </article>
在上面的结构中,我们可以看到使用header我们定义了一篇文章的标题和内容。这里header标签的使用并不是页面的页头,而是文章的页头。
所以在HTML5中,header的使用更加灵活,你可以根据你的需要来定义和组织document结构。
Nav标签
Nav标签全称navigation,顾名思义,是导航的意思。根据HTML5的相关标准定义如下:
"A section of a page that links to other pages or to parts within the page: a section with navigation links."
中文翻译大概意思是”页面中的一个用来链接到其它页面或者当前页面的区域:一个含有导航链接的区域”。
这里非常清楚的定义了nav标签的功能,这里和header类似并没有指定必须是主导航,也可以是页面其它部分的子导航。如下:
<h3>gbin1.com文章列表</h3> <nav> <ul> <li><a href=”#html5“>HTML5文章介绍</a></li> <li><a href=”#css3“>CSS3文章介绍</a></li> <li><a href=”#jquery“>jQuery文章介绍</a></li> <ul> </nav>
在上面这个例子中,我们看到这里只是一个区域的文章导航,同样也可以使用nav定义一个小型的页面内导航。
Footer标签
最后一个就是footer标签,即,页底标签。使用这个标签你可以定义页面的低端结构,当然,和上面我们介绍header标签或者nav标签一样,它并不是仅仅使用在整个页面的页尾处。相关的HTML5标准定义如下:
“ The footer element represents a footer for its nearest ancestor sectioning content or sectioning root element. A footer typically contains information about its section such as who wrote it, links to related documents, copyright data, and the like.”
中文意思是:”footer元素代表了页面内容或者区域内容最底端的展示。一个典型的例子是包含了作者信息,文档链接或者是版权信息等等“。
当然,这里我们看到并不局限于整个页面的内容,也可以是一个文章的页尾内容,例如,来源或者是作者信息等等。如下:
<footer> <div class=”tags“> <span class=”tags-title“>相关标签</span> <a href=”#“ rel=”tag“>html5</a>, <a href=”#“ rel=”tag“>nav</a>, <a href=”#“ rel=”tag“>header</a>, <a href=”#“ rel=”tag“>footer</a> </div> <div class=”source“> <div>来源:<a href=”http://gbin1.com“>html5/css3教程</a></div> </div> </footer>
在上面的例子中,我们定义了一个简单的文章内的页尾信息,可以看到我们添加了来源和相关标签,这在博客类型的网站中经常出现。
一个完整的HTML5页面
在这里我们使用基本的header,nav和footer标签书写了一个响应式的HTML5页面,如果你使用老版本的浏览器,例如IE6,7等等。需要引入相关的js来帮助识别新的元素,当然,你也可以使用下面js代码来简单生成。
/* * 创建HTML5标签 */ document.createElement(”article“); document.createElement(”section“);
总结
相 对于其它的HTML5特性来说,header,nav和footer显得不是那么的酷,当时作为一个前端开发人员来说,如何能够正确的组织页面结构对于一 个逻辑性很强,页面也很复杂的项目来说,意义依旧是非常重大的。希望今天的这篇文章能够帮助大家简单直观的了解这些基本的HTML5标签。
以上就是HTML5/CSS3系列教程:HTML5基本标签使用header,nav和footer的内容,更多相关内容请关注PHP中文网(www.php.cn)!

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.

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

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.

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.

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.

HTML5 is the latest version of the Hypertext Markup Language, standardized by W3C. HTML5 introduces new semantic tags, multimedia support and form enhancements, improving web structure, user experience and SEO effects. HTML5 introduces new semantic tags, such as, ,, etc., to make the web page structure clearer and the SEO effect better. HTML5 supports multimedia elements and no third-party plug-ins are required, improving user experience and loading speed. HTML5 enhances form functions and introduces new input types such as, etc., which improves user experience and form verification efficiency.

How to write clean and efficient HTML5 code? The answer is to avoid common mistakes by semanticizing tags, structured code, performance optimization and avoiding common mistakes. 1. Use semantic tags such as, etc. to improve code readability and SEO effect. 2. Keep the code structured and readable, using appropriate indentation and comments. 3. Optimize performance by reducing unnecessary tags, using CDN and compressing code. 4. Avoid common mistakes, such as the tag not closed, and ensure the validity of the code.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version
Chinese version, very easy to use

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)
