我想显示这样一个以文本对齐为中心的短句。
<p style="font-size: 13px; text-align: center; width: 600px;">
This is a variable-length sentence which is sometimes only a few words and sometimes up to three lines long.
</p>这是一个可变长度的句子,有时只有几个单词,有时长达三行。
现在发生的是,由于宽度,最后两个单词“行长”落在段落的下一行。在中心线上,这看起来相当难看。我目前解决这个问题的方法是在正确的地方手动插入一个中断。
<p style="font-size: 13px; text-align: center; width: 600px;">
This is a variable-length sentence which is sometimes<br/>only a few words and sometimes up to three lines long.
</p>这是一个可变长度的句子,有时
只有几个字,有时长达三行。
这样做总是很累人。HTML中是否有一种自动执行此操作的方法?因此,首先让"p“元素确定显示文本所需的最小行数,然后尽可能地将其水平缩小,同时保持相同的行数?
发布于 2015-07-05 22:10:49
与CSS最接近的是text-align: justify;。
p {
font-size: 13px;
text-align: justify;
}
p#first {
width: 100px;
}
p#second {
width: 150px;
}<p id="first">
This is a variable-length sentence which is sometimes only a few words and sometimes up to three lines long.
</p>
<p id="second">
This is a variable-length sentence which is sometimes only a few words and sometimes up to three lines long.
</p>
https://stackoverflow.com/questions/31235363
复制相似问题