user2574794
user2574794

Reputation: 1006

Keeping a string of text together on one line

Is there a way to keep a string of text on one line, so that if the div width gets to small, the whole string will drop to the next line instead of half of it?

Example:

"Industry Updates - 8th
 September 2013" 

often this happens on mobile browers whereas with to smaller width, the ideal situation is that the whole date stays together giving:

"Industry Updates - 
 8th September 2013" 

So is there a tag to use or a css trick to achieve this? Thanks

Upvotes: 41

Views: 66338

Answers (2)

JSous
JSous

Reputation: 1037

CSS

.nowrap {
    white-space: nowrap;
}

HTML

<span class="nowrap">Industry Updates -</span>
<span class="nowrap">8th September 2013</span>

Any element with white-space: nowrap stays on one line

Upvotes: 87

thgaskell
thgaskell

Reputation: 13256

You want to use a non-breaking space in your HTML markup &nbsp; instead of a normal space.

HTML

"Industry Updates - 8th&nbsp;September&nbsp;2013" 

Upvotes: 56

Related Questions