跨浏览器提示分词



在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>

这个答案有同样的问题——它对我来说在 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>

最新更新