即使您的文档可能未针对该文档类型进行验证,更改 DOC 类型定义是否有任何影响?
目前我们有以下 DOC 类型:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">
有一些举措更改为以下 DOC 类型:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN" >
争论是为了执行严格的 W3C 标准以实现跨浏览器兼容性,我的问题是,如果我们采用新的 DOC 类型,
不将 4.0.1 HTML 定义中仍然存在的部分代码更改为 XHTML 1.0 定义,这还有用吗?
更改为新的 DOC 类型定义会导致我现有的 JSP / HTML 损坏(假设那些完全符合 4.0.1 但未针对 1.0 XHTML 进行测试)?
Currently we have the following DOC type:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">
There are some initiatives to change to the following DOC type:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN" >
The argument is for the enforcement of strict W3C standards for cross browser compatibility, my question is, if we adopt the new DOC type,
without changing parts of the codes that are still in the 4.0.1 HTML definition to XHTML 1.0 definition, will it be of any use?
will changing to the new DOC type definition cause my existing JSP / HTML to break (suppose those that conform to 4.0.1 perfectly but not tested against 1.0 XHTML)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您实际上将以下内容作为新的文档类型:
从功能上讲,您的 JSP/HTML 不会中断。现代网络浏览器足够宽容,它会在需要时关闭打开的标签,并且会接受未指定的属性。但与此同时,您应该真正考虑修复它们,以便尽可能根据新的文档类型进行 w3 验证。
然而,CSS 指定的外观可能会出现重大问题。您的旧文档类型将浏览器推入怪异模式,其中揭示了相当严重的盒子模型错误。由于此错误,MSIE 将元素的
padding
和border
计入元素的width
中。因此,如果您更改此文档类型,您只会在 MSIE 中看到更改。如果您的网站是根据网络标准在普通网络浏览器上设计的(即,它是为 Firefox、Chrome、Safari 等设计的),那么您无需担心。它只会在 MSIE 中看起来像预期的那样,这只是一个优势。
但是,如果您的网站是为 MSIE 设计的,因此忽略了网络标准,那么您必须对 CSS 进行大量更改(主要是宽度/填充/边框/边距),以便它在 MSIE 中看起来与预期的相同。您还将获得额外的优势,即它现在可以在普通浏览器上正常显示。
至于文档类型的选择,这将是主观的,但如果您需要我的意见,请阅读以下答案:
I'll assume that you actually mean the following as the new doctype:
Functionally, your JSP/HTML will not break. The modern webbrowser is forgiving enough and it'll close open tags where needed and it'll accept unspecified attributes. In the meanwhile you should however really consider to fix them anyway so that it w3-validates against the new doctype as much as possible.
However, major problems may arise in look'n'feel as specified by CSS. Your old doctype pushes the the browser in quirksmode which reveals among others the pretty serious box model bug in MSIE. With this bug, MSIE accounts the element's
padding
andborder
into element'swidth
. So if you change this doctype, you'll only see changes in MSIE.If your website was designed on normal webbrowsers according the web standards (i.e., it's been designed for Firefox, Chrome, Safari, etc), then you don't need to worry. It'll only going to look like in MSIE as intented, which is just an advantage.
But if your website was designed for MSIE and hereby thus ignoring the webstandards, then you'll have to make a lot of changes in CSS (mainly width/padding/border/margin) so that it look the same in MSIE as intented. You'll also gain the additional advantage that it will now look properly on normal browsers.
As to the doctype choice, well this is going to be subjective, but if you need my opinion, then read the following answers: