【发布时间】:2021-12-04 00:11:42
【问题描述】:
如何使文本跨越多行,让每个字母在 CSS 中垂直对齐?
我使用 CSS 设置了以下内容。
word-spacing: 0px;
padding: 0px;
letter-spacing: 24px;
我认为发生错位是因为我没有使用等宽字体。
有没有办法强制字体中的所有字符宽度相同以使事情变得更容易?所有这些都可以在跨越多行时垂直对齐?
You can try out the code here.
为了将来参考,我复制了下面的代码。
HTML
<div class="gridpaperfocus">
<p>paragraph one</p>
<p>paragraph two</p>
</div>
CSS
body {
font-family: Tahoma;
}
.gridpaperfocus {
background-image: url('https://i.imgur.com/HezKKmn.png');
background-color: #dcdcdc;
/* font-weight: bold; */
/* max-height: 100px; */
overflow: hidden;
position: relative;
box-sizing: border-box;
border-style: double;
margin: 16px;
/* color: rgb(255, 153, 51); */
color: #3c3c3c;
padding: 0px 30px;
/* padding: 0px; */
word-spacing: 0px;
margin-left: 32px;
letter-spacing: 24px;
line-height: 30px;
display: block;
width: 90%;
}
.gridpaperfocus p {
margin: 0px;
margin-top: 0px;
margin-bottom: 30px; /* 42px with gridpaperback.png */
}
.gridpaperfocus p:last-of-type { margin-bottom: 0px; }
【问题讨论】:
-
提供一些代码。
-
@disinfor 我已经添加了带有 jsfiddle 链接的代码。