<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
nav{
width: 960px;
height: 40px;
margin: 40px auto;
}
ul{
list-style: none;
}
li{
width: 240px;
height: 40px;
float: left;
background-color: #ee5757;
line-height: 40px;
text-align: center;
}
a{
display: block; /* 转成块级元素,设宽高 */
width: 240px;
height: 40px;
text-decoration: none; /*下划线 */
color: aliceblue;
}
a:hover{
border-top: 3px solid #000;
/* 相对定位 向上移动3px */
position: relative;
top: -3px;
background-color: rgb(243, 135, 135);
}
</style>
</head>
<body>
<nav>
<ul>
<li>
<a>网页布局</a>
</li>
<li>
<a>网页布局</a>
</li>
<li>
<a>网页布局</a>
</li>
<li>
<a>网页布局</a>
</li>
</ul>
</nav>
</body>
</html>