How to use HTML and CSS to implement a navigation label layout
Navigation label layout is very common in web design, it allows users to quickly find the page they need, and Improve the navigation friendliness of your website. The following will introduce in detail how to use HTML and CSS to implement a navigation label layout, and attach specific code examples.
<div class="nav"> <ul> <li><a href="#">首页</a></li> <li><a href="#">产品</a></li> <li><a href="#">关于我们</a></li> <li><a href="#">联系我们</a></li> </ul> </div>
.nav { background-color: #f1f1f1; } .nav ul { list-style-type: none; margin: 0; padding: 0; display: flex; justify-content: center; } .nav li { margin: 0 10px; } .nav li a { color: #333; text-decoration: none; } .nav li a:hover { color: #f00; }
Explanation:
.nav
class is a container for navigation labels, by setting background- color
implements the setting of background color. .nav ul
class is an unordered list, and the effect of horizontal arrangement is achieved by setting display: flex
. .nav li
class is a list item, and the interval between list items is achieved by setting margin
. .nav li a
is the link text of a list item. The link font color can be set by setting color
. .nav li a:hover
class is the style when the mouse is hovering, and the link color can be switched by setting color
. <head>
and < body>
between tags. The sample code is as follows: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>导航标签布局</title> <style> /* CSS代码 */ </style> </head> <body> <!-- HTML代码 --> </body> </html>
Through the above four steps, we successfully implemented a simple navigation label layout using HTML and CSS. According to actual needs, the navigation labels can be further expanded and beautified, such as adding drop-down menus, responsive layouts, etc. Hope this article is helpful to you!
The above is the detailed content of How to implement a navigation tag layout using HTML and CSS. For more information, please follow other related articles on the PHP Chinese website!