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>
相关推荐
tomla8 小时前
使用clip-path polygon()画一个多边形
css
生活、追梦者8 小时前
html+css+JavaScript 实现两个输入框的反转动画
javascript·css·html
嫣嫣细语9 小时前
css实现鼠标禁用(鼠标滑过显示红色禁止符号)
前端·css
安冬的码畜日常11 小时前
【CSS in Depth 2精译】2.5 无单位的数值与行高
前端·css
ilisi_11 小时前
导航栏样式,盒子模型
前端·javascript·css
GDAL13 小时前
css之transform-origin
前端·css
疯狂创作者13 小时前
十款绚丽的前端 CSS 菜单导航动画
前端·css
秃头女孩y13 小时前
前端之CSS篇--面试题总结
前端·css
2402_8575834913 小时前
定制化的 CSS 魔法:WebKit 处理 CSS 变量的深度解析
前端·css·webkit
鱼仰泳1 天前
【笔记】解决 CSS:backface-visibility:hidden; 容器翻转 引起的容器内 input不可用
前端·css·笔记