tags:

views:

1844

answers:

7
<div style="height:0px;max-height:0px">
</div>

Setting a div height to 0px does not seem to work.

The div expands to show its contents, how do we prevent this from happening?

+4  A: 

Set overflow:hidden. Otherwise the content will expand the wrapping element.

Gumbo
No, the content will overflow the wrapping element and be visible outside it. The container won't expand (except in some Microsoft browsers (but not in some rendering modes)).
David Dorward
+2  A: 

Try overflow:hidden

Roman
+2  A: 

You could try adding "overflow:hidden" to the style

Philippe Leybaert
+5  A: 

Try to also set line-height: 0;

And if you want to hide your div completely, use display: none;

Philippe Gerber
It sounds like what the OP really wants is "display: none;".
Jon Tackabury
+3  A: 

If you really want to be sure it's gonna be have no height you could use something like this:

display: block;
line-height:0;
height: 0;
overflow: hidden;

If you're still having problems on IE, you could also add

zoom: 1;

to it in a stylesheet targeted at IE with a conditional comment. That'll trigger the hasLayout property in IE.

And display:none isn't the same as setting it to zero height. Just look at the various clearfix solutions for a case where not removing it from the flow is crucial.

Gabriel Hurley
you'd also want to ensure padding: 0;honestly easiest way to handle issues like this is to always start with a reset.css - makes debugging these things for x-browser compliance much easier
knight0323
+1  A: 

You haven't said which browser you're using, but I'm assuming IE, as it's the only browser I know of which mistakes height for min-height . Like everyone else has already said, overflow:hidden; will work, or line-height: 0;, but you only need one of them.

Setting height: 0; will have allready triggered IEs hasLayout, so no need for zoom:1; in this case.

Eystein
A: 

Not quite sure what you're trying to do, out of context, but try this:

display:none;
overflow:hidden:
height:0;
line-height:0;
border:0;
margin:0;
John Bellone