使用vertical-align:middle设置在父元素中的位置:
html+css代码:
<!DOCTYPE html>
<html>
<head lang="zh">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8" />
<title>css让文字垂直居中</title>
<style>
.content {
width: 500px;
margin: 0 auto;
height: 200px;
background: red;
}
.pox {
padding: 10px;
height: 100px;
text-align: center;
display: table-cell;/*将div设置为table-cell*/
vertical-align: middle;/*设置该元素在父元素中的位置*/
background: yellow;
}
</style>
</head>
<body>
<div class="content">
我是div中的文字
<div class="pox">
<a>我是子元素的文字</a>
</div>
</div>
</body>
</html>