tags:

views:

31

answers:

2

Firefox and seems to render a hyphen followed by   differently to other browsers. Here is some test code that demonstrates the problem:

<html>
<body>
    <div style="border: 1px solid blue;width: 50px">
        This text can break. Do&nbsp;not&nbsp;-&nbsp;break&nbsp;this&nbsp;text.
    </div>
</body>
</html>

Notice how in Firefox the second sentence does not break, but in Chrome and IE it breaks at the hyphen.

Does anyone know a good workaround so that the break does not occur?

+3  A: 

The problem is that the "minus" sign in your code allows breaking. There are lots of ways how you can write a "horizontal line" in HTML. &ndash;, &mdash;, -. There is "A list apart" article describing all the possible ways.

But also several specific Unicode characters exist which can be used by their code point numbers. One of them is a "non-breaking hyphen", which can be written like this: &#8209;.

I tried using it in your example and now the text does not break.

naivists
A: 

Naivist has the answer, but, for the record, I ended up using CSS's white-space: nowrap;

cbp