<!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;
}
ul{
background-color: black;
width: 300px;
height: 135px;
margin: 10px;
}
li a{
display: inline-block;
width: 300px;
padding: 12px 16px;
text-decoration: none;
color:white;
}
li a:hover{
background-color: orange;
color: aliceblue;
}
</style>
</head>
<body>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">News</a></li>
<li><a href="#">Contact</a></li>
</ul>
</body>
</html>
思路:
1.首先给导航框创建一个盒子
2.在盒子中加入列表标签输入导航栏内容
3.在<head>标签中定义元素样式<style>
4.格式化内外边距,项目符号,字体样式
5.设置列表的宽高边距
6.设置列表内容的宽高边距,因为<a>元素是行类元素,不可设置宽高,所有应先转换为块元素显示模式再设置其宽高对齐
7.将列表内容垂直居中
8.最后用伪元素设置鼠标放在内容上样式