Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting div max height doesn't work

Tags:

html

css

I have this simple HTML

<html>
<head>
    <style>
    </style>
</head>
<body>
<div style="position: relative; overflow: visible; width: 100%; height: 100%;" class="surface">
    <div style="width: 300px; max-height: 2px; height: 2px; position: absolute; left: 36.165px; top: 0.8957px; border: 1px solid red;"></div>
    <div style="width: 1px; height: 200px; position: absolute; left: 30.165px; top: 47.8957px; border: 1px solid red;"></div>   
</div>
</body>
</html>

There are basically two divs: one "horizontal" (height 2px) and one "vertical" (height 2px).

When I view the page on firefox:

enter image description here

while on IE (8) something weired happens:

enter image description here

the top DIV is not 2px high.

Any idea why is that so ?

like image 861
Majid Laissi Avatar asked Nov 11 '12 23:11

Majid Laissi


2 Answers

Your possible solutions :

1). Add display: block to your style

2). check you have a proper DOCTYPE otherwise (IE) quirks mode will produce unexpected format and results. Check this article for reference

like image 149
JFK Avatar answered Nov 15 '22 23:11

JFK


Your problem appears to stem from ie's quirks mode mode.

It occurs when there is no doctype declaration. Max height, among other things (including the box model) acts as if it were ie5. A simple solution is to add a doctype declaration:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
like image 45
Tyzoid Avatar answered Nov 15 '22 21:11

Tyzoid