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>
相关推荐
慕钦。2 小时前
图像滑块对比功能的开发记录
前端·javascript·css·html5
烂蜻蜓4 小时前
深入理解 HTML 元素:构建网页的基础
开发语言·前端·css·html·html5
伊泽瑞尔.11 小时前
使用css变量实现更改字体大小功能(vue3为例)
前端·css
少吃一口都不行12 小时前
css不出现滚动条
前端·javascript·css
凉生阿新20 小时前
【CSS】Tailwind CSS 与传统 CSS:设计理念与使用场景对比
css
IT、木易21 小时前
大白话CSS 中的box-sizing属性,它有哪些值以及各自的作用
前端·css·面试
yzy8521 小时前
HTML页面中divborder-bottom不占用整个底边,只占用部分宽度
css·html·html5
zhenryx1 天前
前端-css(预编译器sass)
前端·css·sass
剪刀石头布啊1 天前
css精灵图(sprite)
前端·css
前端婴幼儿1 天前
一个前端vue3文字hover效果
前端·css·vue