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>
相关推荐
用户268348422395910 分钟前
前端换肤功能最佳实践:从基础实现到高级优化
前端·css
蓝婷儿3 小时前
第二章支线八 ·CSS终式:Tailwind与原子风暴
前端·css
Java永无止境4 小时前
Web前端基础:HTML-CSS
java·前端·css·html·javaweb
超级土豆粉5 小时前
CSS 性能优化
前端·css·性能优化
Sun_light7 小时前
用原生 HTML/CSS/JS 手把手带你实现一个美观的 To-Do List 待办清单小Demo
前端·css·html
Bottle4147 小时前
你真的懂 CSS 吗?一文看懂“层叠”的底层机制!(含 MDN 原文解读)
css
普宁彭于晏8 小时前
CSS3相关知识点
前端·css·笔记·学习·css3
Vinceri8 小时前
VSCode主题定制:CSS个性化你的编程世界
css·ide·vscode
一小条咸鱼9 小时前
CSS预处理器:Sass与Less的语法和特性(含实际案例)
css·less·sass