Non-breakingtext

20060823231

A few months ago I ran into a case where I needed a few words to never break across lines despite line length or text size. My only thought was wrapping those words in a span tag with a class defining whitespace: nowrap;. Using span‘s can feel dirty but given a proper class name it could add some semantic value to those words. Plus adding the class to a header tag could avoid the span all together if the entire line can’t be broke.

Recently I realized the same effect could be achieved using the HTML entity for a non-breaking space. That’s what it is supposed to be used for. It’s one of those entities that just brings back thoughts of poor code and jimmy-rigged alignment – essentially I never realized it actually had a legitimate purpose. At the same time though sticking a bunch of  ‘s in the HTML seems worse than going the span route. It works nice for two or three words but any more makes the code hard to read.

Take this example. Even given the “duh” factor of realizing   could be used for this, I’m still leaning towards always using a class applied to a wrapper regardless of the word count.


Skateboards and bikes are better at nights

Skateboards and bikes are better at nights. 0 comments.


Search WayTooCrowded
The Header Should Always Point Home