40

So I have the text e-commerce and I don't want the line to wrap at the dash.
How would I restrict wrapping for that text line?

Edward Falk
  • 9,685
  • 9
  • 73
  • 108
Kirk Strobeck
  • 17,015
  • 18
  • 74
  • 109

4 Answers4

92

You could use CSS: white-space: nowrap;.

Example: Wrap the text in a span with that CSS declaration.

<span style="white-space: nowrap;">e-commerce</span>

Paul Sham
  • 3,145
  • 2
  • 23
  • 31
60

Use the non-breaking hyphen: &#8209;

Benny Neugebauer
  • 46,191
  • 22
  • 218
  • 190
Michael Lorton
  • 41,023
  • 26
  • 92
  • 136
19

Wrap it in the <nobr>…</nobr> tag, or if you care out the validity of your HTML, set the white-space: nowrap; style.

David Wolever
  • 139,281
  • 83
  • 327
  • 490
  • 4
    I think `` tags are deprecated. Edit: I was not the downvoter though. – Paul Sham Aug 28 '11 at 04:21
  • *If* you care about validity?!? I wasn't the downvoter, but if I were, I wouldn't reverse it on those grounds. – Michael Lorton Aug 28 '11 at 04:27
  • 3
    nobr is deprecated, but it shouldn't be. That's a plain screw-up by the World Wide Web Consortium. – Dave Burton Apr 28 '14 at 10:12
  • 1
    Hadn't heard of it, but `` works everywhere I tried - and better than the other options... It's like, we - never got to know each other... and now it's too late? Say it isn't so! – sheriffderek Jun 26 '15 at 01:24
6

There is this non-breaking hyphen (copy and paste it): or use &#8209; or &#x2011;

Note that this is the only unicode “character” which unifies the following characteristics:

  • is pre-composed (you can make anything non-breaking by composition)
  • is non-breaking
  • is a hyphen or dash or similar


The usage of the word joiner represented by &#8288; or &#x2060; allows for other hyphens. Results:

e‐⁠commerce (hyphen followed by word joiner)
e‑⁠commerce (ASCII hyphen/minus followed by word joiner)
...and the precomposed one for reference:
e‑commerce (non-breaking hyphen)

http://jsfiddle.net/NR5Ch/58/   (this fiddle shows the effect of the word joiner)

Robert Siemer
  • 29,185
  • 9
  • 77
  • 89