我试图证明这个 p 标签中的文本是正确的,以便它完全适合 p 的宽度。
<p align="justify" style="text-align: justify !important; color:#fff; margin:0px; font-weight:bold; width:487px; border:Solid 1px red;">blah blah blah</p>
但文字只是不能证明!知道为什么吗?
谢谢你的帮助。
我试图证明这个 p 标签中的文本是正确的,以便它完全适合 p 的宽度。
<p align="justify" style="text-align: justify !important; color:#fff; margin:0px; font-weight:bold; width:487px; border:Solid 1px red;">blah blah blah</p>
但文字只是不能证明!知道为什么吗?
谢谢你的帮助。
您可以使用此处描述的解决方案:http: //blog.vjeux.com/2011/css/css-one-line-justify.html
这将使单行对齐,但在之后添加一个空格,因此如果您知道高度,您可以指定它overflow:hidden
来隐藏它并仍然得到对齐。
.fulljustify {
text-align:justify;
}
.fulljustify:after {
content: "";
display: inline-block;
width: 100%;
}
#tagline {
height: 80px;
overflow: hidden;
line-height: 80px; /* vert-center */
}
<p id="tagline" class="fulljustify">Blah blah blah</p>
如果您的文本不超过一行,则对齐不会做任何事情。您的文本必须换行到下一行,然后第一行将是合理的,但不是第二行。
Chrome 不支持,但在 Firefox 和 IE 中,您可以使用text-align-last: justify;
. 对于跨浏览器解决方案,我们必须使用@onemanarmy 发布的内容;)
如果你想证明四个单词 in487px
你可以尝试word-spacing
在你的css
.
我用过word-spacing:8em;
,bla bla bla bla
但您可以根据需要进行调整。
尝试这个
对于 div
div {
text-align:justify;
text-justify: inter-word;
text-align-last:center;
/* for IE9 */
-ms-text-align-last:center;
}
还有类似的东西,比如 display: flex; justify-content:空间环绕;如果您将这些文本包装在 span 或 div 中
在我的情况下 < p > 标签,使用简单的方法:
p {
text-align: justify;
text-justify: inter-word;
}
让它在 Chrome 和 opera 上看起来不错(多行对齐在它们上看起来很糟糕)
我使用以下
.fulljustify {
text-align: justify;
display: table-row;
text-align-last: left;
}
你最好试试
style="text-align:justifty;display:inline-block;"
只需使用style="text-align:justify"
.
它适用于所有浏览器。