tags:

views:

1034

answers:

8

Can I prevent text in a div block from overflowing?

+8  A: 
<div id="myDiv">
    stuff 
</div>

#myDiv {
    overflow:hidden;
}

Give that a try. And check out the docs for the overflow property.

inkedmn
Great online sourse! Thank you very much!
Nope, not great at all...
Those aren't "the docs", that's a web site with some basic information about HTML/CSS. The docs are at w3.org
DisgruntledGoat
Don't be pedantic. That page very clearly explains the use of the property in question.
inkedmn
+1  A: 

overflow: scroll ? Or auto. in the style attribute.

bean
+3  A: 

I think your question is answered in the documentation of the css overflow property.

Otto Allmendinger
+1  A: 

Yes. You can use CSS - There are a bunch of values you can use..

http://www.w3schools.com/Css/pr_pos_overflow.asp

inkedmm is right, that might be the behavior you want, but you should determine if that is the case.

Dave Morgan
+1  A: 
.NonOverflow
{
    width: 200px; /* Need the width for this to work */
    overflow: hidden;
}

<div class="NonOverflow">
    Long Text
</div>
Kirtan
in multilingual text other than, it causes some characters of long words be hidden from display.
Bhupi
+6  A: 

You can control it with CSS, there is a few options :

  • hidden -> All text overflowing will be hidden.
  • visible -> Let the text overflowing visible.
  • scroll -> put scroll bars if the text overflows

Hope it helps.

Timothée Martin
Thanks a lot! That is nice of you.
A: 

If your div has a set height in css that will cause it to overflow outside of the div.

You could give the div a min-height if you need to have it be a minimum height on the div at all times.

Min-height will not work in IE6 though, if you have an IE6 specific stylesheet you can give it a regular height for IE6. Height changes in IE6 according to the content within.

Sir David of Lee
A: 

If you want the overflowing text in the div to automatically newline instead of being hidden or making a scrollbar, use the

word-wrap: break-word

property.

Rujiel