html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>相对定位</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="father">
<div class="page1">
<a href="#">链接1</a>
</div>
<div class="page2">
<a href="#">链接2</a>
</div>
<div class="page3">
<a href="#">链接3</a>
</div>
<div class="page4">
<a href="#">链接4</a>
</div>
<div class="page5">
<a href="#">链接5</a>
</div>
</div>
</body>
</html>
css
.father{
border: 2px solid red;
height: 300px;
width: 300px;
padding: 10px;
}
.page1{
height: 100px;
width: 100px;
background-color: pink;
display: block;
}
.page1:hover{
background-color: blue;
}
.page1 a{
text-decoration: none;
color: white;
line-height: 100px;
text-align: center;
display: block;
}
.page2{
height: 100px;
width: 100px;
background-color: pink;
display: block;
position: relative;
left: 200px;
top: -100px;
}
.page2:hover{
background-color: blue;
}
.page2 a{
text-decoration: none;
color: white;
line-height: 100px;
text-align: center;
display: block;
}
.page3{
height: 100px;
width: 100px;
background-color: pink;
display: block;
}
.page3:hover{
background-color: blue;
}
.page3 a{
text-decoration: none;
color: white;
line-height: 100px;
text-align: center;
display: block;
}
.page4{
height: 100px;
width: 100px;
background-color: pink;
display: block;
position: relative;
left: 200px;
top: -100px;
}
.page4:hover{
background-color: blue;
}
.page4 a{
text-decoration: none;
color: white;
line-height: 100px;
text-align: center;
display: block;
}
.page5{
height: 100px;
width: 100px;
background-color: pink;
display: block;
position: relative;
left: 100px;
top: -300px;
}
.page5:hover{
background-color: blue;
}
.page5 a{
text-decoration: none;
color: white;
line-height: 100px;
text-align: center;
display: block;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/987eda963db3265fd647c060efb84f0a.png)