1.利用 text-align: justify;属性使文字两端对齐
// css .justify-w4 { text-align: justify; width: 70px; display: inline-block; height: 18px; } .justify-w4::after { content: ""; display: inline-block; width: 100%; }
<-- HTML --> <p><span class="justify-w4">电视机</span></p> <p><span class="justify-w4">性感漂亮</span></p> <p><span class="justify-w4">手机</span></p>
2.利用letter-spacing
// css .w4 { text-align: center; width: 4em; } .w2{ letter-spacing:2em; /*如果需要y个字两端对齐,则为(x-y)/(y-1),这里是(4-2)/(2-1)=2em */ margin-right:-2em; /*同上*/ } .w3{ letter-spacing:0.5em; /*如果需要y个字两端对齐,则为(x-y)/(y-1),这里是(4-3)/(3-1)=0.5em */ margin-right:-0.5em; /*同上*/ }
<-- HTML -->
<p><span class="w3">电视机</span></p>
<p><span class="w4">性感漂亮</span></p>
<p><span class="w2">手机</span></p>