views:

77

answers:

2

So I've got this markup:

<div id="text-container">
  <p></p>
</div>

with this style (redundant, I know):

#text-container {display:block: width:220px; height:280px;}
#text-container p {display:block; width:220px; height:60px;}

and this bit of jQuery plugging simple content into the paragraph:

$("#text-container p").text(data);

Works in Firefox. The text wraps and stays inside the set width of the paragraph. But not in any version of IE. In IE 7/8, the text continues horizontally out of the paragraph even though the paragraph itself adheres to the set dimensions. In IE 6, not only does the text spill out horizontally, but it stretches the paragraph with it. I've tried using .html instead of .text, but that didn't work. Not ideal. Did I mention not ideal? Does anyone know how to get around this? Thanks.

+1  A: 

Try adding overflow: hidden; to the paragraph element's style

#text-container p {display:block; width:220px; height:60px; overflow:hidden;}
Ryan McGeary
Huh... I tried to edit your answer, only to find you'd deleted it while I was editing. So I posted my own. And now it's back. Oh well... Have an up-vote for being quick; not sure why you were down-voted.
Shog9
Yeah, I temporarily revoked it after the downvote thinking I misread the question. +1 for your answer.
Ryan McGeary
'overflow:hidden;' was one of the first things I tried, but it chops off the overflowing text and I lose it. any other ideas?
echobase
@echobase: I *suspect* you need to add more breaking spaces to your text, but without an example can't really be sure.
Shog9
+1  A: 

This is a known bug in IE6:

IE6 and lower implements overflow: visible incorrectly.

The correct behaviour is that the element with overflow: visible becomes as high and wide as the CSS orders, and that any content that doesn't fit spills out of the box, overlapping, if necessary, the content that follows.

Note that the behavior you're seeing in IE7 and IE8 could be considered correct (although not terribly friendly, at least if the text fails to wrap when it could wrap).

To achieve consistent behavior, try Ryan McGeary's suggestion: add overflow: hidden; to the style of the element you wish to constrain:

#text-container {display:block; width:220px; height:280px; overflow:hidden;}
#text-container p {display:block; width:220px; height:60px; overflow:hidden;}

Note that I've also corrected an errant colon in your original style - no idea if that was in your actual code, or merely a typo when composing your question...

Shog9