CSS _text-align:justify;实现两端对齐

本文介绍了一种使用CSS实现标签和输入框对齐的方法。首先尝试使用`text-align-last: justify;`来对齐文本,但由于兼容性问题,最终采用绝对定位和伪元素的方式实现了效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考:https://segmentfault.com/q/1010000007136263

法一:text-align-last:justify;

html

<div>
        <p class="item">
            <label for="name" class="itemLabel">姓名</label>
            <input type="text" class="itemContent" id="name">
            
        </p>
        <p class="item">
            <label for="phone" class="itemLabel">手机号</label>
            <input type="text" class="itemContent" id="phone">
        </p>
        
 </div>

css

 .itemLabel{
            display: inline-block;
            width: 60px;
            text-align-last:justify;
    }

由于text-align-last的兼容性问题:https://caniuse.com/#search=text-align-last,需要使用法二实现:

css

        .item{
            position: relative;
        }
        .itemContent{
            position: absolute;
            left:70px;
        }
        .itemLabel{
            display: inline-block;
            width: 60px;
            text-align: justify;
        }
       .itemLabel:after{
            display: inline-block ;
            content: ''; 
            width: 100%;
        }

 

转载于:https://www.cnblogs.com/LinSL/p/8607069.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值