css 文字两端对齐

复制代码
<body>
    <div class="box">
        <p>姓名</p>
        <p>性与别</p>
        <p>家庭住址</p>
        <p>how are you</p>
        <p>hello</p>
        <p>1234</p>
        <p>1 2 3 4</p>
    </div>
</body>
  • text-align: justify;

  • text-align-last: justify;

    <style> .box { display: flex; justify-content: center; align-items: center; flex-direction: column; width: 500px; height: 500px; border: 1px solid #000; } p { width: 130px; border: 1px solid #000; text-align: justify; text-align-last: justify; /*兼容ie*/ text-justify: distribute-all-lines; } </style>
  • 设置 text-align: justify; 伪元素 after或者 before的样式,伪元素中可以添加width:100% 或padding-left:100%

    <style> .box { display: flex; justify-content: center; align-items: center; flex-direction: column; width: 500px; height: 500px; border: 1px solid #000; } p { height: 30px; width: 130px; border: 1px solid #000; text-align: justify; } p::after { content: ""; display: inline-block; /* width: 100%; */ padding-left: 100%; } </style>
相关推荐
拾光拾趣录6 小时前
Flexbox 布局:从“垂直居中都搞不定”到写出响应式万能布局
前端·css
编程猪猪侠8 小时前
Tailwind CSS 自定义工具类与主题配置指南
前端·css
Sherry00710 小时前
CSS Grid 交互式指南(译)(下)
css·面试
Hilaku13 小时前
深入background-image:你可能不知道的几个性能优化与高级技巧
前端·css
睡不着先生13 小时前
CSS `@scope` 实战指南:开启局部样式隔离新时代
css
gnip16 小时前
实现elementplus官网主题切换特效
前端·css
前端老鹰17 小时前
CSS scroll-snap-type:让滚动定位精准如 “自动吸附” 的魔法
前端·css
涔溪1 天前
响应式前端设计:CSS 自适应布局与字体大小的最佳实践
前端·css
代码的余温1 天前
CSS3文本阴影特效全攻略
前端·css·css3
每天开心2 天前
告别样式冲突:CSS 模块化实战
前端·css·代码规范