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>
相关推荐
JYeontu11 小时前
轮播图不够惊艳?试下这个立体卡片轮播图
前端·javascript·css
软件技术NINI17 小时前
泉州html+css 4页
前端·javascript·css·html
ZC跨境爬虫20 小时前
跟着 MDN 学CSS day_2:(连接样式表与选择器的实战艺术)
java·前端·css·ui·html·媒体
ZC跨境爬虫20 小时前
跟着 MDN 学CSS day_1:(CSS 基石与色彩的艺术)
前端·javascript·css·ui·html
艾伦野鸽ggg21 小时前
CSS 滤镜与动态特性知识梳理
前端·css
小杍随笔1 天前
【Rust + Tauri 2 + TypeScript + Tailwind CSS 4 桌面应用 UI 组件选型深度对比(2026版)】
css·rust·typescript
希冀1231 天前
【CSS学习第十篇】
前端·css
biubiubiu_LYQ2 天前
萌新小白基础篇之CSS定位布局(干货满满)!
css
暗冰ཏོ2 天前
CSS 超详细讲解(从基础到高级实战)
前端·css·css3·sass·scss
超人气王2 天前
一文搞懂css定位布局,轻松掌握布局核心逻辑
前端·css