当您必须支持 IE6 时,是否可以拥有符合 W3C 标准的代码?w3
我试图激励我的团队成员验证我们的代码,但似乎有些失望,因为我们仍然需要支持 IE6。
对此大家有什么想法吗?
这就是我想要的:
- 语义代码 - 是
- 验证代码 - 是
- 适用于 IE6 - 是
我们不要在这里争论语义哈哈。 =]
HTML JS CSS
I'm trying to motivate my team members to get our code to validate, but there seems to be some disillusionment because we are required to still support IE6.
Do you guys have any thoughts to this end?
This is what I'm going for:
- Semantic code - YES
- Validating code - YES
- Works in IE6 - YES
Let's not argue over semantics here lol. =]
HTML JS CSS
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,您可以拥有完全兼容的代码,并将 IE6 的残渣保留在单独的文件中(通常):
只需使用 IE 条件语句隐藏任何 IE6 特定代码即可。如果您希望 CSS 仍然有效,这是首选方法。此外,所有有效的 HTML 都应该在 IE6 中正常工作,并通过 CSS 应用正确的样式:
这将对所有验证器隐藏,并且代码的其余部分可以保持有效。
事实上,由于条件注释只是 HTML 注释,因此即使该代码仍然有效。
编辑:
证明这一点的唯一方法是构建一个示例,但这三个方法都可以通过 IE6 和适当的编码知识实现。
事实上,不仅 IE6 存在有效代码问题,IE6 和 IE7(以及 IE8)也存在问题,但同样,仅在 CSS 中。验证您的主要 CSS 文件,但将 IE6 CSS 与条件分开。
我很少需要向 HTML 添加额外的标记来支持 IE6(除了
head
中的条件)。这只是理解盒模型并相应地构建语义页面的问题。如果一两个
div
呈现出正确的分组,那么它们并不是邪恶的。三个嵌套的div
来修复bug
是邪恶的:)Yes, you can have fully compliant code, and keep the cruft for IE6 in a separate file (normally):
Just hide any IE6 specific code with IE conditional statements. This is the preferred way to do it if you want your CSS to still validate. Additionally, all valid HTML should work fine in IE6 with the proper styling applied via CSS:
That will be hidden from all validators, and the rest of your code can remain valid.
In fact, since the conditional comment is just that, a HTML comment, even that code is still valid.
EDIT:
The only way to prove this would be to build an example, but all three are possible with IE6 and proper knowledge in coding.
In fact, its not just IE6 that presents a problem with valid code but both IE6 and IE7 (and IE8), but again, only in the CSS. Validate your main CSS files but keep IE6 CSS separate with conditionals.
Rarely do I have to add extra markup to the HTML to support IE6 (other than conditionals in the
head
). It is simply a matter of understanding the box model, and building your semantic pages accordingly.One or two
divs
are not evil if they present a proper grouping. Three nesteddivs
to fix abug
is evil :)简短的回答:是的!
根据我的经验,有效的语义标记实际上在 IE6 中效果更好。将其与正确、有效且简单的 CSS 结合起来,您就已经非常出色了。当然,您肯定会在 IE6 中遇到一些奇怪的行为,尤其是对于更复杂的设计,如上所述。然而,大多数这些错误都是有据可查。使用简单、有效的代码,识别和解决这些问题通常相当简单。
如上所述,条件注释当然有效,但是开发有效的代码将阻止您在代码中加入各种条件。
还是无法发挥作用吗?优雅地降级!当然,圆角很漂亮而且很流行,但是 20%(希望更少)仍然生活在黑暗时代的用户可能不会错过它们。
Short answer: yes!
It's been my experience that valid, semantic markup actually works better with IE6. Combine this with correct, valid, and simple CSS and you're pretty much golden. Sure you're bound to encounter some strange behavior in IE6, especially for more complex designs, as noted above. However, most of these bugs are well documented. With simple, valid code, identifying and fixing these issues is often fairly simple.
Conditional comments, as noted above, certainly work, but developing valid code will prevent you from peppering your code with all sorts of conditions.
Still can't make it work? Degrade gracefully! Sure rounded corners are pretty and all the rage, but the 20% (hopefully less) of your users who are still living in the dark ages probably won't miss them.
让代码在 IE6 中工作需要做一些工作,让代码验证也需要一些工作,但这并不意味着它们是同一种工作,或者其中一个会使另一个变得不可能。
实际上没有任何内容表明代码必须通过验证才能在 IE6 中运行。相反,验证的代码更有可能在任何浏览器中运行,而不仅仅是 IE6。您可以使用无效代码来规避一些 IE6 怪癖,但这并不是规避这些问题的唯一方法。当新的浏览器版本发布时,使用有效代码的方法也更有可能继续工作,这样您就不必为每个新的浏览器更新重新开始。
如果您不必同时考虑有效代码,那么让代码在 IE6 中运行当然会更容易,但这只是因为需要考虑的因素更多,而不是因为这些因素本身不兼容。
It's a bit of work to make the code work in IE6, and there is a bit of work to make the code validate, but that doesn't mean that it's the same kind of work or that one of them will make the other impossible.
There isn't really anything that says that the code has to fail validation to work in IE6. On the contrary, code that validates is more likely to work in any browser, not just IE6. There are some IE6 quirks that you can circumvent using non-valid code, but it's not the only method for circumventing the problems. Methods that use valid code are also more likely to continue working when new browser versions are released, so that you don't have to start over for every new browser update.
It's of course easier to make the code work in IE6 if you don't have to think about valid code at the same time, but that's just because there are more factors to consider, not because the factors are incompatible per se.
不,对于任何中等复杂的布局都是不可能的。
编辑:至少在不添加大量难看的条件的情况下是这样。
No, it is not possible for any moderately complex layout.
EDIT: At least not without adding lots of ugly conditionals.