0

I don't see why a simple overflow in a div doesn't work.

<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
<style type="text/css">
.ename {width:400px;overflow:hidden;padding:0 5px 0 5px;color:#EE3129;line-height:25px;text-transform:uppercase;}
</style>
</head>
<body>
<div class="ename"> qksdjlqjsdkqsd qksdjlkqsjdklqsjd qsdkjqslkdjkqsjdklqsjd sdkqsjdkqsjdkqjsdkqd qdlkjqsdkjqskdjkqlsjdkqs qsdkjqskdj </div>
</body>
</html>

Thank you

3
  • 1
    Actually, it is showing the expected behaviour. What do you expect it to happen? How should it be for you? Just doesn't work won't give the expected stuff. Commented Oct 11, 2012 at 9:45
  • You should give it a height property so the text wouldn't try to fit itself within the given width, giving respect to the given height of the cotnainer. Commented Oct 11, 2012 at 9:46
  • @AlainZelink: If you see, most of the answers are conveying to use the white-space: nowrap; CSS property. Commented Oct 11, 2012 at 9:58

4 Answers 4

4

Text will always wrap before it overflows. Your page is behaving as expected. If you want it to always stick to one line, you'll want white-space: nowrap.

http://jsfiddle.net/Tc2wA/

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

Comments

2

Use white-space: nowrap; CSS

If you want to make the text in a single line and it shouldn't go out, you need to use white-space: nowrap; CSS.

Code

<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type">
<style type="text/css">
  .ename {width:400px;overflow:hidden;padding:0 5px 0 5px;color:#EE3129;line-height:25px;text-transform:uppercase; white-space: nowrap;}
</style>
</head>
<body>
<div class="ename"> qksdjlqjsdkqsd qksdjlkqsjdklqsjd qsdkjqslkdjkqsjdklqsjd sdkqsjdkqsjdkqjsdkqd qdlkjqsdkjqskdjkqlsjdkqs qsdkjqskdj </div>
</body>
</html>

And that shows your output this way:

Nowrap

Demo: http://jsbin.com/ocacuw/1

Comments

2

set height what ever you want

.ename {width:400px;
overflow:hidden;
padding:0 5px 0 5px;
color:#EE3129;
line-height:25px;
text-transform:uppercase;
height: 58px;}

Demo: fiddle

Comments

0

The text in the div is not overflowing because it can simply wrap and expand the divs height. If you add white-space: nowrap; to the css, you will see that the text overflows.

Or, if you want the text to wrap to some extent, just add height: 20px; or any height value to the style.

Comments

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.