我使用了特殊字符 '#' '_'和'\'用于 IE 浏览器兼容性。但现在我的样式表由于使用 IE hack 而在 W3c 验证中失败
我使用特殊字符“#”“_”和“\”来兼容 IE 浏览器。但现在由于使用了 IE hack,我的样式表在 W3c 验证中失败了。无论如何,是否有具有浏览器兼容性的无错误样式表。
现在我无法删除这些 IE hack,因为我的 HTML 文件现在正在 Java 程序开发中。
我的黑客是这样的:
/* For IE8 */top:-15px;
/* 对于 IE7 */#top:-10px;
/* 对于 IE6 */_top:-1px;
I used special character '#' '_' and '\' for IE browser compatibility. But now my style sheet is fail in W3c validation because of using IE hack. Is there anyway for error less stylesheet with browser compatibility.
Now I am not able to remove these IE hack because of my HTML files are now in Java program development.
My hack are like this :
/* For IE8 */top:-15px;
/* For IE7 */#top:-10px;
/* For IE6 */_top:-1px;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
是的,不要使用无效的 CSS hack,它们非常脆弱。
对于拿起IE的具体情况,条件注释更好。大多数解决方案都会在 CC 中放置额外的样式表,但如果您不想这样做,您可以使用 CC 进行类切换:
然后根据类在一个位置执行所有样式:(
这是假设 IE8 是“全部”)对”,并且应遵循与其他浏览器相同的规则,因此“下层显示”CC 允许其他人看到无类
。)
Yeah, don't use invalid CSS hacks, they're super-fragile.
For the specific case of picking up IE, conditional comments are better. Most solutions put extra stylesheets in CCs, but if you don't want to do that you can do class-switching with CCs:
and then do all your styling in one place based on the class:
(This is assuming that IE8 is “all right” and should be served the same rules as other browsers, hence the ‘downlevel-revealed’ CC that allows everyone else to see the classless
<body>
.)在条件语句中使用特定的 html 页面。
您的参考
Used the particular html page in conditional statement.
Your reference
将您对 IE 的调整分解为单独的样式表,并通过 条件注释,例如对于 IE8 样式表:
Factor your adaptions for IE out into separate style sheets, and include them via conditional comments, e.g. for the IE8 style sheet:
我想说不要太担心验证。
当尝试找出某些内容何时损坏时使用它会很有帮助,但这不是任何网站的目标。
为什么不使用条件注释,而不是在CSS中进行修改呢?
您可以在其中放置单独的样式或样式表的链接。
不管怎样,只有 8 以下的 IE 才能看到。
http://msdn.microsoft.com/en-我们/library/ms537512(v=vs.85).aspx
I would say don't worry too much about validation.
It is helpful to use when trying to figure out when something is broken, but not the goal of any Web site.
Instead of hacks within your css, why not use conditional comments?
You can either place individual styles in there or a link to a stylesheet.
Either way, only IE less than 8 sees it.
http://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx
还有一种不带条件注释的解决方案,它允许您将所有 CSS 规则存储在一个文件中。
对于 IE8,您不需要任何 CSS hack;它是一个对 CSS 2.1 支持非常好的浏览器。尽管如此,如果您确实需要一个值,您可以尝试设置一个值,然后使用一些 IE8 无法识别的 CSS3 选择器重写它。
There is also a solution without the conditional comments, which allows you to store all CSS rules in one file.
For IE8, you shouldn't need any CSS hacks; it's a browser with very good CSS 2.1 support. If you, despite this fact, do need one, you may try setting a value with no hack and then rewrite it using some CSS3 selector that won't be recognized by IE8.