CSS实现简易导航
- 首先搭建html骨架
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>我的导航</title>
</head>
<body>
</body>
</html>
- 添加导航内容,使用nav+a实现
<nav>
<a href="#">Java</a>
<a href="#">PHP</a>
<a href="#">Ruby</a>
<a href="#">Python</a>
</nav>
- 添加样式
nav {
height: 41px;
background-color: #fcfcfc;
border-top: 3px solid #ff8500;
border-bottom: 1px solid #edeef0;
}
nav a {
font-size: 14px;
color: #4c4c4c;
text-decoration: none;
height: 41px;
line-height: 41px;
padding: 0 15px;
display: inline-block;
}
nav a:hover {
background-color: #ccc;
}
- 完整源码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>新浪导航</title>
<style>
nav {
height: 41px;
background-color: #fcfcfc;
border-top: 3px solid #ff8500;
border-bottom: 1px solid #edeef0;
}
nav a {
font-size: 14px;
color: #4c4c4c;
text-decoration: none;
height: 41px;
line-height: 41px;
padding: 0 15px;
display: inline-block;
}
nav a:hover {
background-color: #ccc;
}
</style>
</head>
<body>
<nav>
<a href="#">首页</a>
<a href="#">手机新浪网</a>
<a href="#">网站导航</a>
<a href="#">李元芳</a>
</nav>
</body>
</html>
-
效果图
网站导航
李元芳
```
- 效果图
![image-20230430091308210](https://i-blog.csdnimg.cn/blog_migrate/31d19e6b93548086cbc128cedff5164a.png)