适当的 DTD 可以解决这个问题吗?
我遇到了跨浏览器兼容性问题,并找到了一个名为“浏览器兼容性检测器”的 Chrome 插件。它建议添加 DTD 以在标准模式下呈现页面。
我添加了这一点:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
它带来了新问题并修复了其他问题,但至少现在所有浏览器的工作方式都差不多。
然而,它仍然建议为另一个问题添加 DTD:
In IE6 IE7(Q) IE8(Q), the container will be enlarged when its 'width' or 'height' is not big enough to hold all its contents
Content box's size in Chrome: 1366 * 0, in IE: 1366 * 653.
Suggestion: Use a DTD that makes the page rendered in Standards Mode, so that only IE6(S) will be affected.
我应该添加什么类型的文档类型?直到 5 分钟前我什至不知道它们的存在,所以我不知道该写什么。
I was having problems with cross-browser compatibility and found out a plugin called "Browser Compatibilty Detector" for Chrome. It recommended adding a DTD to renders the page in standards mode.
I added this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
It brought new issues and fixed others but at least now all browsers are working kinda the same.
However it's still recommending adding a DTD for another issue:
In IE6 IE7(Q) IE8(Q), the container will be enlarged when its 'width' or 'height' is not big enough to hold all its contents
Content box's size in Chrome: 1366 * 0, in IE: 1366 * 653.
Suggestion: Use a DTD that makes the page rendered in Standards Mode, so that only IE6(S) will be affected.
What type of doctype should I add? I didn't even know they existed until 5 minutes ago so I have no idea what to write.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您仅添加 HTML5 docytype
,
以便您的代码将来友好,然后开始查明并修复出现的跨浏览器问题。
另外,如果您不需要支持 IE6 和 IE7 等旧版浏览器,那么您可以开始忽略它们。检查你的统计数据,看看支持是否值得。
I suggest you add the HTML5 docytype only
<!DOCTYPE html>
so that your code will be future friendly AND then start pinpointing and fixing the cross-browser issues that crop up.
Also, if you do not need to be supporting legacy browsers like IE6 and IE7, then you can start to ignore them. Check you stats to see if support is even merited.
最初是一个 SGML 指令,它定义(直接或通过引用)文档的语言及其可能的结构。如今,在讨论它在浏览器中激活的渲染/解析模式时可能最常提到它。
http://hsivonen.iki.fi/doctype/
这是一篇关于不同 doctype 声明的总体不错的文章对于 HTML 文档。它有一些关于不同模式的背景信息和一个表示什么文档类型激活什么模式的表格。一般来说,最佳实践是使用与您的 HTML/XHTML 版本匹配(或与您的版本兼容)的文档类型声明并触发浏览器中的标准模式。
<!DOCTYPE ... >
was originally an SGML directive that defined (directly or by reference) the language of the document and its possible structure. Nowadays it is probably most often mentioned in discussions on what rendering/parsing mode it activates in the browser.http://hsivonen.iki.fi/doctype/
That is a generally nice article on different doctype declarations for HTML documents. It has some background information about different modes and a table denoting what mode is activated by what doctype. Generally the best practice is to use a doctype declaration that matches your HTML/XHTML version (or one compatible with yours) and triggers the standards mode in browsers.