0

I'm trying to make something 100% height and adding a doctype breaks that. That was explained on other questions. However, I found something weird -- if I close the doctype tag (which I know you're not supposed to do) then 100% height works again on both chrome and IE. What exactly is happening then? Does closing the doctype mean the doctype is being ignored?

    <!doctype html/> <!--You're not supposed to close doctype but if you do, then 
the 100% sizing works. Why?-->
<html>
<body>
    <!--This 100% height won't work with a normal doctype but closing
    the doctype makes it work?-->
    <div style="border:5px solid black;height:100%">This should be 100%</div>
</body>
</html>
Community
  • 1
  • 1
user1167362
  • 21
  • 2
  • 3

1 Answers1

1

According to 8.1.1 The DOCTYPE,

A DOCTYPE must consist of the following components, in this order:

  1. A string that is an ASCII case-insensitive match for the string "
  2. One or more space characters.
  3. A string that is an ASCII case-insensitive match for the string "html".
  4. Optionally, a DOCTYPE legacy string or an obsolete permitted DOCTYPE string (defined below).
  5. Zero or more space characters.
  6. A ">" (U+003E) character.

Therefore, your "closed doctype" is an invalid doctype. And thus it's like you had no doctype at all.

Oriol
  • 274,082
  • 63
  • 437
  • 513