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?
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.
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.
You could also put non-breaking spaces ( ) 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
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 ; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With