HTML 文档中提到的所有链接均未放置在 内。元素;它只包括主要的导航块。它也可用于定义网站页脚中的链接,但
HTML 元素不允许嵌套在 中元素。
HTML5 中的导航标签需要开始和结束标签,即 ……..
语法:
HTML/XHTML
<nav> ... </nav>
CSS
nav{
--your css code—
}
使用标签
;标签专为主要导航区域而设计,例如页面或部分顶部的主菜单。一个文档可以有多个 元素。 元素,即一个用于站点导航,一个用于页面内导航等。标签可以是 ul 列表中的代码,也可以简单地编码为不带 ul 元素的单独链接。此标签有助于更轻松地创建导航菜单、文本链接的整洁水平菜单或帮助屏幕阅读软件以正确识别文档中的主要导航区域等内容。
<title>HTML Nav tag</title>
<header>
<h1 id="About-Us">About Us</h1>
</header>
<nav>
<a href="https://www.educba.com/about-us/">Who is EDUCBA?</a> |
<a href="https://www.educba.com/careers/">Careers</a> |
<a href="https://www.educba.com/instructors/">Become an instructor</a> |
<a href="https://www.educba.com/how-it-works/">How does it work?</a> |
</nav>
Output:
Example #2
HTML Tag helps the users navigate to the main sections of the website.
<style>
nav{
display:flex;
flex-wrap:wrap;
}
nav a {
text-decoration: none;
display:block;
padding: 15px 25px;
text-align: center;
background-color: rgb(213, 216, 220);
color:#566573;
font-family:sans-serif;
}
nav a:hover {
background-color: #566573;
color:#ffffff;
}
</style>
<h1 id="Example-of-the-HTML-nav-tag">Example of the HTML nav tag:</h1>
<nav>
<a href="https://www.educba.com/about-us/">About</a>
<a href="https://www.educba.com/tutorials/">Tutorials</a>
<a href="https://www.educba.com/courses/">Certification Courses</a>
</nav>
Output:
Example #3
Tables of contents and menus are good examples of HTML element.
<style>
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul:after {
clear: both;
display: block;
}
nav ul li {
float: left;
position:relative;
list-style-type:none;
}
nav ul li:hover {
background: rgb(52, 73, 94);
}
nav ul li:hover a {
color: #fff;
}
nav ul li a {
display: block;
padding: 20px 30px;
color: #ffffff;
text-decoration: none;
background-color:rgb(40, 55, 71 );
font-family: sans-serif;
}
nav ul ul {
background: #5f6975;
padding: 0;
position: absolute;
top: 100%;
}
nav ul ul li {
float: none;
position: relative;
}
nav ul ul li a {
padding: 15px 10px;
color: #ffffff;
text-transform: uppercase;
}
nav ul ul li a:hover {
background: rgb(27, 38, 49);
}
</style>
<h1 id="Dropdown-menu-with-the-HTML-nav-tag">Dropdown menu with the HTML nav tag:</h1>
<nav>
<ul>
<li>
<a href="https://www.educba.com/about-us/">About</a>
<ul>
<li>
<a href="#">Reviews</a>
</li>
<li>
<a href="#">Contact</a>
</li>
<li>
<a href="#">About Us</a>
</li>
</ul>
</li>
<li>
<a href="https://www.educba.com/tutorials/">Tutorials</a>
<ul>
<li>
<a href="#">Finance</a>
</li>
<li>
<a href="#">Data Science</a>
</li>
<li>
<a href="#">Sofware Development</a>
</li>
<li>
<a href="#%22">Design</a>
</li>
<li>
<a href="#">Excel</a>
</li>
<li>
<a href="#">Others</a>
</li>
</ul>
</li>
<li>
<a href="https://www.educba.com/courses/">Certification Courses</a>
<ul>
<li>
<a href="#">Finance</a>
</li>
<li>
<a href="#">Data Science</a>
</li>
<li>
<a href="#">Sofware Development</a>
</li>
<li>
<a href="#%22">Design</a>
</li>
<li>
<a href="#">Excel</a>
</li>
<li>
<a href="#">Others</a>
</li>
</ul>
</li>
</ul>
</nav>
Output:
Browser Support: The section tag is being new in HTML5, and it is being supported in the browser, which is listed below:
Google Chrome 6.0
Internet Explorer 9.0
Firefox 4.0
Opera 11.1
Safari 5.0
Conclusion- Html Nav Element
Below are mentioned some of the main key points which you should remember from this topic:
The element in HTML5 represents a section of the page whose entire purpose is to provide navigational links, either in the same document or any other document. The links in the element can point to other webpages or to different sections of the same webpage. Common examples of the nav elements are tables, menus, indexes, and contents.
The HTML element can use for the primary navigation of the structure.
Some developers might use the HTML element for breadcrumbs and paginations.
Essentially, it is your own perception of how to use the element within your HTML document.