Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

div Height: 0 problem in IE

to clear: both my content i use this:

CSS:

.clr {
  clear: both;
  height: 0; /* i have tried 0.001em to */
  line-height: .001em;
  overflow: hidden;
}

HTML:

<div class="clr">&nbsp;</div>

it works perfectly in every navigator. But in IE 7 & 8 the div still have a height of a few pixels. How can i avoid this?

like image 975
meo Avatar asked May 28 '10 07:05

meo


People also ask

Why does my div have zero height?

The reason why the height or the containers is 0 is because you are floating all the content inside them and floated elements don't expand the height (or width) of their parents.

Why is the height of div not changing?

If you have not set an explicit height to the containing block (and the child is not absolutely positioned), then your child element with percentage height will have nothing to go on and height will be determined by content and other properties.

How do you set a div to 100% height?

With the advent of the CSS flex model, solving the 100% height problem becomes very, very easy: use height: 100%; display: flex on the parent, and flex: 1 on the child elements. They'll automatically take up all the available space in their container.


2 Answers

It's a IE font problem.

Add

font-size: 0;

to your css declaration

like image 183
Ben Avatar answered Oct 05 '22 21:10

Ben


Just coming across this and the answer Ben gave makes sense but it was incomplete in dec of 2011 on IE 7 (legacy support necessitates this.

font-size:0; is a good start but didn't initially do it for me.

Along this line of thought, you need to be mindful of line-height. If you set line-height higher up in the DOM, likely due to the nature of these things, it get inherited ( as was happening to me )

If you have set line-height on a parent, be sure to set it explicitly on the child you are trying to use to force the clear:

font-size:0;
line-height:0;

-Brandt

like image 20
Brandt Solovij Avatar answered Oct 05 '22 20:10

Brandt Solovij