views:

56

answers:

3

How can I have a div of static 60px height in Internet Explorer?

A: 
<div style="height: 60px;">This is my div</div>
Emil Vikström
If the contents are bigger then 60px, the div will auto-resize.
cypher
+4  A: 
<div style="height: 60px; overflow: hidden;">Hello, World</div>

Some versions of IE don't follow max-height, unfortunately, and that's where overflow: hidden comes in handy. Note that the div will ALWAYS have 60px height no matter what's inside it.

cypher
+3  A: 
#el {
    height:expression(this.scrollHeight>59?"60px":"auto");     
}
meder
This is an excellent solution. Why is there scrollHeight instead of just height?
cypher
"An element's scrollHeight is a measurement of the height of an element's content including content not visible on the screen due to overflow." - I'm sure clientHeight could also be used as well but I thought maybe this was necessary.
meder
Expressions no longer work in IE9 and I thought they no longer worked in IE8 so this is a horrible idea.
Rob