1. Vertically center multi-line text:
<div>
<span>随便写点什么拿来测试</span>
</div>
div{
width: 100px;
height: 100px;
margin: 100px auto;
border: 1px solid #000;
display: table;
}
span{
line-height: 20px;
display: table-cell;
vertical-align: middle;
}
As shown in the figure:
2. Clear the gap: For example, there will be a gap between the content written in the span of two lines
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div >
<span>123</span>
<span>456</span>
</div>
</body>
</html>
As shown in the figure, this is because a newline will render a space. If two spans are written on the same line, there will be no gap, but it is not in line with our habits, then use css to solve it:
div{
font-size: 0;
}
span{
font-size: 16px;
}