设置display: inline-block;的标签i与span标签一起会导致元素垂直不对齐,通过给i标签设置伪类before,content的不可为空,从而实现垂直居中。
未设置伪类before
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
.head-left .icon-wodeditu{
background: #5daaff;
width: 30px;
height: 30px;
border-radius: 100%;
color: #fff;
line-height: 30px;
display: inline-block;
text-align: center;
.head-left .icon-wodeditu:before{
/*content: "111";*/
.head-left .title{
color: #3c3d3f;
margin: 0 10px;
font-size: 16px;
</style>
</head>
<div class="head-left">
<i class="icon-wodeditu"></i>
<span class="title">我的可视化地图</span>
</body>
</html>
设置伪类before
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
.head-left .icon-wodeditu{
background: #5daaff;
width: 30px;
height: 30px;
border-radius: 100%;
color: #fff;
line-height: 30px;
display: inline-block;
text-align: center;
.head-left .icon-wodeditu:before{
content: "111";
.head-left .title{
color: #3c3d3f;
margin: 0 10px;
font-size: 16px;
</style>
</head>
<div class="head-left">
<i class="icon-wodeditu"></i>
<span class="title">我的可视化地图</span>
</body>
</html>