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>
相关推荐
ヤ鬧鬧o.5 小时前
多彩背景切换演示
前端·css·html·html5
这儿有一堆花7 小时前
CSS 拟真光影设计:从扁平到深度的技术复盘
前端·css
_OP_CHEN8 小时前
【前端开发之CSS】(三)CSS 常用元素属性宝典(上):从字体到文本,手把手教你打造高颜值网页!
前端·css·html·网页开发·文本属性·字体属性·页面美化
朝阳3913 小时前
CSS-in-JS(含样式化组件 styled-components)
css
ヤ鬧鬧o.13 小时前
HTML多倒计时管理
前端·javascript·css·html5
码上出彩13 小时前
H5+CSS3响应式设计实战:基于Flex布局的适配方案
前端·css·css3
倪枫13 小时前
CSS3——文本样式(字体样式和文本布局)
前端·css·css3
木斯佳13 小时前
周末杂谈:Chrome CSS 2025-声明式Web的革命之年
前端·css·chrome
朝阳3914 小时前
CSS【模块】CSS Modules
css
PieroPc14 小时前
FastAPI 和 Html+css+js 开发的 PDF打印服务器 连接到服务器的物理打印机打印
css·html·fastapi