Martin Burch
Martin Burch

Reputation: 2921

Cross-browser hinting for word break

In Chrome, I can specify where I want my text to wrap with a combination of <wbr> and white-space: nowrap;. But in Firefox or IE the text just flows out of the box and <wbr> is ignored. Is Chrome interpreting the spec properly or is this just a quirky, if useful, implementation bug? Is there a cross-browser solution for text-wrap hinting?

.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 has the same problem—it doesn't work in Firefox for me.

Upvotes: 0

Views: 475

Answers (1)

Martin Burch
Martin Burch

Reputation: 2921

Here's an implementation of a suggestion from @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>

Upvotes: 1

Related Questions