代码:
<!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>
a {
/* 去除下划线 */
text-decoration: none;
color: white;
/* 设置背景颜色 */
background-color: pink;
/* 行内块模式,在一行还能设置大小 */
display: inline-block;
width: 100px;
height: 30px;
/* 文字水平居中 */
text-align: center;
/* 设置文字的高度 重要:行高就是等于高度,文字能够居中 */
line-height: 30px;
}
a:hover{
/* 鼠标经过设置颜色变化 */
background-color: orange;
}
</style>
</head>
<body>
<a href="#">体育</a>
<a href="#">娱乐</a>
<a href="#">汽车</a>
</body>
</html>
其中涉及单文本垂直居中line-height:30px、行内块元素display:inline-block、文字水平居中text-align:center等内容。