8

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?

1
  • have you tried word-wrap and white-space: nowrap css property..? Commented Nov 27, 2013 at 3:38

2 Answers 2

19

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

Sign up to request clarification or add additional context in comments.

2 Comments

@JoshC Haha, revenge! :P
0

You can try using white-space : nowrap.

Example is available below

<span>lorem sum etc ger ergdfg efdfg</span>

<style>
span
{
    width:100px;
    height:auto;
    overflow:scroll;
    display:inline-block;
    white-space : nowrap;
}
</style>

1 Comment

This answer doesn't really offer anything more than the answer offered by Doorknob. Can you expand on the answer and include explanations for why this code should be used?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.