【发布时间】:2015-10-24 15:40:07
【问题描述】:
我有以下代码:
.clJustify {
width: 400px;
height: 25px;
margin-left: auto;
margin-right: auto;
border: 1px solid red;
text-align: justify;
}
.clJustify:after {
content: "";
display: inline-block;
width: 100%;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Justify Test</title>
</head>
<body>
<p class="clJustify">This is text that should be jus-</p>
<p class="clJustify">tified and also hyphenated.</p>
</body>
</html>
请不要问我为什么要这样做。 :-)
我的问题是:在 FF 和 Chrome 中,这会导致两行文本填满 <p> 的空间。但是 IE 打破了“jus-”之前的第一行并将其放入单独的行中。没有连字符的行将按预期显示,似乎是末尾的连字符使 IE 感到困惑。
这是 Internet Explorer 的屏幕截图:
这是来自 Firefox 的屏幕截图:
有什么办法可以防止 IE 中断吗?对旧帖子的建议答案并未解决 连字符 的问题。
【问题讨论】:
-
好吧,我不是问你为什么要这样做,而是你只想这样做吗?
-
如果有其他方法可以证明单行的合理性,我将不胜感激。
-
对齐单行?我有个主意。试试
text-align-last,用sn-p给你写一个答案。 -
您可以尝试使用不同类型的破折号(U+2010 到 U+2015),看看它们是否有相同的怪癖...
标签: html css internet-explorer justify hyphen