HTML sin salto de línea en guiones

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?

preguntado el 28 de agosto de 11 a las 04:08

4 Respuestas

Podrías usar CSS: white-space: nowrap;.

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

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

Respondido 28 ago 11, 08:08

only then it will not wrap at all which is not the intended result. - Fantasma de Madara

… uuhh… what? blah blah <span style="white-space: nowrap;">e-commerce</span> will work just fine =\ - David Wolever

I am adding an example, it's not as clean as the &#8209; aunque método. - Paul Sham

Due to the title of the question, everyone is coming to this page from google searching for this answer, not caring about hyphens. - Nick Manning

I took the liberty of fixing that. - Edward Falk

Use the non-breaking hyphen: &#8209;

Respondido 26 Oct 14, 16:10

+1. It works. Didn't know that. Here's a fiddle to show: jsfiddle.net/jasongennaro/NR5Ch - Jason Gennaro

@Rikudo Sennin -- my first SO drag-race victory (I've been an also-ran dozens of times)! And OP, I just Googled it myself. If you didn't have success there, you may want to read este. - Malvolio

The downside of that is that searching the page for "e-commerce" will not find the string. - Alexei Danchenkov

@AlexeiDanchenkov - It depends on the sophistication of your browser, yes. - Malvolio

@Malvolio well, Chrome 65 is not sophisticated enough to see hyphen and &#8209; or &#2011; as the same symbol. - Alexei Danchenkov

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

Respondido 28 ago 11, 08:08

Creo que el <nobr> tags are deprecated. Edit: I was not the downvoter though. - Paul Sham

If you care about validity?!? I wasn't the downvoter, but if I were, I wouldn't reverse it on those grounds. - Malvolio

nobr is deprecated, but it shouldn't be. That's a plain screw-up by the World Wide Web Consortium. - Dave Burton

Hadn't heard of it, but <nobr> 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

There is this non-breaking hyphen (copy and paste it): o usar &#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


El uso de la word joiner representado por &#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)

contestado el 11 de mayo de 15 a las 14:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.