参考:https://segmentfault.com/q/1010000007136263
法一:text-align-last:justify;
html
1<div> 2 <p class="item"> 3 <label for="name" class="itemLabel">姓名</label> 4 <input type="text" class="itemContent" id="name"> 5 6 </p> 7 <p class="item"> 8 <label for="phone" class="itemLabel">手机号</label> 9 <input type="text" class="itemContent" id="phone"> 10 </p> 11 12 </div>
css
1 .itemLabel{ 2 display: inline-block; 3 width: 60px; 4 text-align-last:justify; 5 }
由于text-align-last的兼容性问题:https://caniuse.com/#search=text-align-last,需要使用法二实现:
css
1 .item{ 2 position: relative; 3 } 4 .itemContent{ 5 position: absolute; 6 left:70px; 7 } 8 .itemLabel{ 9 display: inline-block; 10 width: 60px; 11 text-align: justify; 12 } 13 .itemLabel:after{ 14 display: inline-block ; 15 content: ''; 16 width: 100%; 17 }