Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prevent text to line break if overflow

Tags:

css

I do not want to specify the width of an area and set overflow:hidden or scroll to my text because the site is responsive. is there any way to prevent a line of text go to second line?

or example "lorem sum etc ger ergdfg efdfg"

will not become

"lorem sum etc ger 
ergdfg  efdfg"

when width is small?

like image 250
user3033162 Avatar asked Nov 27 '13 03:11

user3033162


People also ask

How do I stop texts from breaking?

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).

Which property can be used to insert line breaks within words to prevent text from overflowing?

The overflow-wrap CSS property applies to inline elements, setting whether the browser should insert line breaks within an otherwise unbreakable string to prevent text from overflowing its line box.

How do you prevent newline?

The white-space property has numerous options, all of which define how to treat white space inside a given element. Here, you have set white-space to nowrap , which will prevent all line breaks.

How do I stop text from going to a new line in CSS?

To prevent the text from wrapping, you can use the CSS white-space property with the “nowrap” or “pre” value. In this snippet, you can see examples with both of them.


1 Answers

Use

white-space: nowrap;

on the element containing the text.

The name is pretty self-explanatory - it makes the whitespace not wrap.

Use overflow: hidden; if you don't want the text to go out of the box it's supposed to be in.

Use text-overflow: ellipsis; if you want ellipsis when the text overflows the bounding box.

JSFiddle

screenshot

like image 174
tckmn Avatar answered Sep 21 '22 16:09

tckmn