<! DOCTYPE html> prevents relative css heights
(Everything is tested in the latest firefox.)
This html code creates a red border that fills almost the screen:
<html>
<head>
</head>
<body>
<div style="height:100%;background-color:red;"></div>
</body>
</html>
But adding a doctype declaration disables relative heights and makes the div height equal to zero:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div style="height:100%;background-color:red;"></div>
</body>
</html>
Why is this? In particular, I don’t understand why browsers consider relative heights in the document without doctype, since they are not specified in explicit html tags.
+2
3 answers
The above answer is why, if you were looking for a fix by setting the absolute position and applying top, right, left and bottom, do the trick:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div style="position: absolute;height:100%;background-color:red;bottom: 0;top: 0;right: 0;left: 0"></div>
</body>
</html>
0