Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep a line of text as a single line - wrap the whole line or none at all

Tags:

html

css

I'd like to keep a line of text together such that either the whole line drops down a line or none at all

Acceptable

How do I wrap this line of text - asked by Peter 2 days ago 

Acceptable

How do I wrap this line of text  - asked by Peter 2 days ago 

Not acceptable

How do I wrap this line of text - asked by Peter  2 days ago 

Is this achievable in CSS?

like image 974
Peter Nixey Avatar asked Jul 12 '11 15:07

Peter Nixey


People also ask

How do you keep text in one line?

You could also put non-breaking spaces ( ) in lieu of the spaces so that they're forced to stay together. As Paul Hiles noted above this also works well unless the amount of text cannot be displayed on one line in which case it is cut off.

How do I put text on a single 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.


2 Answers

You could also put non-breaking spaces (&ampnbsp;) in lieu of the spaces so that they're forced to stay together.

How do I wrap this line of text - asked by Peter 2 days ago 
like image 33
substate Avatar answered Sep 17 '22 18:09

substate


You can use white-space: nowrap; to define this behaviour:

// HTML: 

.nowrap {    white-space: nowrap ;  }
<p>        <span class="nowrap">How do I wrap this line of text</span>        <span class="nowrap">- asked by Peter 2 days ago</span>      </p>
// CSS: .nowrap {   white-space: nowrap ; } 
like image 117
Gus Avatar answered Sep 18 '22 18:09

Gus