目标效果:
我们只在css中设置text-align:center 只能让文字左右居中,要实现文字垂直方向也达到居中的效果,我们可以再设置一个line-height,让行高等于块的高度即可
下面附上上图实现代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>热词</title>
<style>
a {
background-color:#3064bb;
text-align: center;
line-height: 80px;
width: 200px;
height: 80px;
font-size: 18px;
color: white;
display: block;
text-decoration: none;
}
a:hover{
background-color: #608dd9;
}
</style>
</head>
<body>
<a href="#">HTML</a>
<a href="#">CSS</a>
<a href="#">JavaScript</a>
<a href="#">Vue</a>
<a href="#">React</a>
</body>
</html>