为 HTML 5 + 所有浏览器选择 DOCTYPE
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2899427/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Selecting a DOCTYPE for HTML 5 + all browsers
提问by Alex
I'm using some HTML5 features on a web page and wondered what the best DOCTYPE is. Currently, this is the DOCTYPE and XMLNS:
我在网页上使用了一些 HTML5 功能,想知道最好的 DOCTYPE 是什么。目前,这是 DOCTYPE 和 XMLNS:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
Should I use the new HTML 5 DOCTYPE?
我应该使用新的 HTML 5 DOCTYPE 吗?
<!DOCTYPE html>
Will older browsers (IE7, FF 2.x) recognize and render the page correctly? What's the best practice in this situation? Thanks.
较旧的浏览器(IE7、FF 2.x)能否正确识别和呈现页面?在这种情况下,最佳做法是什么?谢谢。
采纳答案by ChrisD
Yes, older browsers will work fine. The reason "<!DOCTYPE html>" was chosen in HTML 5 is because it is the smallest a doctype can be and yet still trigger standards compliance mode on those browsers you mention.
是的,旧浏览器可以正常工作。在 HTML 5 中选择“<!DOCTYPE html>”的原因是因为它是最小的文档类型,但仍会在您提到的浏览器上触发标准合规模式。