Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping a string of text together on one line

Tags:

html

css

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

like image 289
user2574794 Avatar asked Sep 12 '13 01:09

user2574794


People also ask

How do I keep text on the same line?

Head to the Insert tab, click the Symbol drop-down arrow, and select “More Symbols.” In the Symbol window, click the Special Characters tab. Select “Nonbreaking Hyphen” in the list, click “Insert,” and then “Close.” You should then see your text adjust with the hyphenated word together on the same line.

How do I put content on one line?

If you want to limit the text length to one line, you can clip the line, display an ellipsis or a custom string. All these can be done with the CSS text-overflow property, which determines how the overflowed content must be signalled to the user.

How do I keep text on the same line in HTML?

To get all elements to appear on one line the easiest way is to: Set white-space property to nowrap on a parent element; Have display: inline-block set on all child elements.

How do you make text not break in HTML?

If you want to prevent the text from wrapping, you can apply white-space: nowrap; Notice in HTML code example at the top of this article, there are actually two line breaks, one before the line of text and one after, which allow the text to be on its own line (in the code).


2 Answers

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

like image 89
JSous Avatar answered Oct 01 '22 09:10

JSous


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"  
like image 26
thgaskell Avatar answered Oct 01 '22 09:10

thgaskell