直接上代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
#a1{/*id选择器*/
width: 300px;
height: 300px;
border: 1px solid red;
margin: auto ;
position: relative;
top: 30px;
}
a{/*标签选择器*/
width: 100px;
height: 100px;
background: pink;
text-decoration: none;
/*改为块元素
*/
display: block;
text-align: center/*字体在中间,但是上下还没有在中间*/;
line-height: 100px;/*行间距 一共100,设置100就是在中间*/
color: black;
border-radius: 10px;
}
a:hover{
background: deepskyblue;
}
.k2,.k4{
position: relative;/*相对定位*/
left:200px;
top:-100px;
}
.k5{
position: relative;/*相对定位*/
left:100px;
top:-300px;
}
</style>
</head>
<body>
<div id="a1">
<a class="k1" href="#">链接1</a>
<a class="k2" href="#">链接2</a>
<a class="k3" href="#">链接3</a>
<a class="k4" href="#">链接4</a>
<a class="k5" href="#">链接5</a>
</div>
</body>
</html>
效果图