css 实现单行文字两端对齐

来源:互联网 发布:自动生成条形码软件 编辑:程序博客网 时间:2024/05/21 06:43

1、问题:给单行文字设置  text-align: justify;  样式时  不起作用。

例:<div class="box">两端对齐</div>

<style>
        .box {
            width: 150px;
            height: 30px;
            line-height: 30px;
            margin: 50px auto;
            background-color: green;
            color: #fff;
            text-align: justify;
        }
    </style>

效果:


2、解决方法:

.box:after {
            content: '';
            width: 100%;
            display: inline-block;
        }


效果:

原创粉丝点击