css overflow - only 1 line of text

homerun picture homerun · Sep 25, 2011 · Viewed 218.7k times · Source

I have div with the following css style:

width:335px; float:left; overflow:hidden; padding-left:5px;

When I insert, into that div, a long line of text, it's breaking to a new line and displays all the text. What I want is to have only one line of text that will not line-break. When the text is long, I want this overflowing text to disappear.

I was thinking about setting the height but it seems to be wrong.

Maybe if I add height that is the same as the font, it should work and not cause any problems in different browsers?

How can I do that?

Answer

Septnuits picture Septnuits · Sep 25, 2011

If you want to restrict it to one line, use white-space: nowrap; on the div.