跨浏览器提示分词
Cross-browser hinting for word break
在 Chrome 中,我可以使用 <wbr>
和 white-space: nowrap;
的组合指定我希望文本换行的位置。但在 Firefox 或 IE 中,文本直接从框中流出,<wbr>
被忽略。 Chrome 是否正确解释了规范,或者这只是一个古怪但有用的实现错误?是否有文本换行提示的跨浏览器解决方案?
.headline-container {
width: 50%;
border: 1px solid red;
}
h1 {
white-space: nowrap;
}
@media (max-width: 400px) {
h1 {
white-space: normal;
}
}
<div class="headline-container">
<h1>This headline could <wbr>wrap in the middle <wbr>but only on Chrome</h1>
</div>
This answer 有同样的问题——它在 Firefox 中对我不起作用。
这是@CBroe 建议的实现...
.headline-container {
width: 70%;
border: 1px solid red;
}
.h1-line {
display: inline-block;
}
@media (max-width: 400px) {
.h1-line {
display: inline;
}
}
<div class="headline-container">
<h1><span class="h1-line">This headline could</span> <span class="h1-line">wrap in the middle</span></h1>
</div>
在 Chrome 中,我可以使用 <wbr>
和 white-space: nowrap;
的组合指定我希望文本换行的位置。但在 Firefox 或 IE 中,文本直接从框中流出,<wbr>
被忽略。 Chrome 是否正确解释了规范,或者这只是一个古怪但有用的实现错误?是否有文本换行提示的跨浏览器解决方案?
.headline-container {
width: 50%;
border: 1px solid red;
}
h1 {
white-space: nowrap;
}
@media (max-width: 400px) {
h1 {
white-space: normal;
}
}
<div class="headline-container">
<h1>This headline could <wbr>wrap in the middle <wbr>but only on Chrome</h1>
</div>
This answer 有同样的问题——它在 Firefox 中对我不起作用。
这是@CBroe 建议的实现...
.headline-container {
width: 70%;
border: 1px solid red;
}
.h1-line {
display: inline-block;
}
@media (max-width: 400px) {
.h1-line {
display: inline;
}
}
<div class="headline-container">
<h1><span class="h1-line">This headline could</span> <span class="h1-line">wrap in the middle</span></h1>
</div>