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>
相关推荐
aaaweiaaaaaa4 小时前
HTML和CSS学习
前端·css·学习·html
xcnn_4 小时前
前端入门——案例一:登录界面设计(html+css+js)
前端·css·html
ST.J4 小时前
前端笔记2025
前端·javascript·css·vue.js·笔记
前端Hardy7 小时前
HTML&CSS:有趣的漂流瓶
前端·javascript·css
前端Hardy7 小时前
HTML&CSS :惊艳 UI 必备!卡片堆叠动画
前端·javascript·css
toooooop88 小时前
本地开发环境webScoket调试,保存html即用
前端·css·websocket
前端Hardy9 小时前
只用2行CSS实现响应式布局,比媒体查询更优雅的布局方案
javascript·css·html
小菜全9 小时前
uniapp基础组件概述
前端·css·vue.js·elementui·css3
心一信息11 小时前
ThreeJS骨骼示例
css·css3·html5
jason_yang15 小时前
基于BEM规范实现ElementPlus组件
css·scss