一個(gè)可以使文字(中文)兩端對(duì)齊的方法。
- 在兩行文字的下方插入一個(gè)元素误趴,寬度填滿空間,令文字與這個(gè)元素兩端對(duì)齊凉当。
- 設(shè)定文字高度枣申,再利用
overflow: hidden;
將插入的元素隱藏。
實(shí)現(xiàn)效果如下
代碼
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>文字兩端對(duì)齊</title>
<style>
div{
border: 1px solid red;
font-size: 20px;
}
span{
border: 1px solid green;
display: inline-block;
width: 5em;
text-align: justify;
line-height: 20px;
overflow: hidden;
height: 20px;
}
span::after{
content: '';
display: inline-block;
width: 100%;
border: 1px solid blue;
}
</style>
</head>
<body>
<div>
<span>姓名</span> <br>
<span>聯(lián)系方式</span>
</div>
</body>
</html>
附加知識(shí)
在div內(nèi)中間沒有斷開的文檔默認(rèn)是會(huì)超出邊界忠藤,可以設(shè)置word-break: break-all;
令其強(qiáng)行斷開。