I often see this doctype declaration on some pages that I am viewing
<!DOCTYPE html>
I made some soft research and this is HTML 5 doctype declaration. Modern browsers can int开发者_如何学Cerpret this and would force to operate on Standards Mode.
My question is, some of my target users are still using IE6. How will IE6 responds when I declare such doctype declaration.?
Will I gain any benefit or loss in that case?
Thanks.
Short answer: the HTML5 doctype works fine in IE6.
Longer answer: see Henri Sivonen's comprehensive research of the effects of different doctypes on different browsers.
There are no downsides to using the HTML5 doctype in IE6. The benefit is a shorter doctype that is easier to remember.
However, IE has an odd bug where if you use HTML5 tags that it doesn't already recognize, they can't be styled with CSS. The browser will act like the tag isn't there. The contents will still render fine though.
To work around this bug, if you call createElement
with the name of the HTML5 tag you want to use in your page, the browser will then allow you to style them with CSS. So if you do this:
document.createElement('video');
Before any <video />
tags on your page, it will allow you to apply proper styling to the tag. Keep in mind the browser still won't actually do anything with the tag. You'll just be able to apply CSS to it.
In order to make this process easier, it is common practice to use this HTML5 shim library on your page. Just include this in your document before any CSS or HTML5 elements.
<!--[if lt IE 9]>
<script src="dist/html5shiv.js"></script>
<![endif]-->
精彩评论