<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
*{
box-sizing: border-box;
list-style: none;
text-decoration: none;
padding: 0;
margin: 0;
}
a{
display: inline-block;
width: 90px;
height: 40px;
color: white;
padding-top: 8px;
}
a:hover{
background-color: orange;
}
.a{
background-color: black;
width: 280px;
height: 40px;
text-align: center;
}
</style>
</head>
<body>
<div class="a">
<a href="#">Home</a>
<a href="#">News</a>
<a href="#">Contact</a>
</div>
</body>
</html>
思路:
1.设置一个盒子装<a>标签水平导航栏内容
2.初始化内外边距,字体样式
3.设置盒子宽高
4.因为<a>标签是行内元素不可设置宽高边距,所有改变显示模式为行内块元素,设置内容宽高边距
5.将内容居中适当调整边距