1、float
<style>
.nav {
overflow: hidden;
background-color: aqua;
}
.nav c {
float: left;
display: block;
text-align: center;
padding: 10px 20px;
text-decoration: none;
color: black;
}
.nav c:hover{
background-color: chartreuse;
}
</style>
<div class="nav">
<c href="#">博客</c>
<c href="#">下载</c>
<c href="#">学习</c>
<c href="#">社区</c>
</div>
2.flex布局
<style>
.nav {
display: flex;
background-color: azure; /* 导航栏背景颜色 */
}
.nav a {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
padding: 14px 16px;
text-decoration: none;
color: #555555; /* 导航栏文字颜色 */
}
.nav a:hover {
background-color: aqua; /* 鼠标悬停时的背景颜色 */
}
</style>
<div class="nav">
<a href="#">首页</a>
<a href="#">关于</a>
<a href="#">服务</a>
<a href="#">联系我们</a> /*导航栏内容填充*/
</div>