条件 CSS 文件不会覆盖常规 CSS
如果 IE 版本低于 8,我将使用条件注释链接到 css 文件(我们称之为“IEonly.css”)。我试图覆盖常规 css 文件中的一些属性。奇怪的是,IEonly.css 会正确设置新的 css 属性,但不会覆盖常规 CSS 文件中的属性!
(我正在尝试使此功能适用于 IE7)。
帮助!
编辑:我在 css 样式后添加了 !important 来看看它是否有帮助。事实并非如此。
I am using conditional comments to link to a css file (let's call it "IEonly.css") if the IE version is less than 8. I am trying to override some properties in the regular css file. Strangely enough, IEonly.css will set new css properties correctly, but it won't override the properties in the regular CSS file!
(I am trying to make this work for IE7).
Help!
EDIT: I added an !important after the css style to see if it would help. It didn't.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
给定多个样式表(即使某些样式表通过条件注释对其他浏览器隐藏),则 的正常规则级联将适用。
确保您的选择器适当具体,并且以正确的顺序应用样式表。
Given multiple stylesheets (even if some are hidden from other browsers with conditional comments) then the normal rules of the cascade will apply.
Make sure your selectors are suitably specific, and that you apply the stylesheets in the right order.
如果您在两个样式表中使用相同的选择器,那么只要将条件 IE 样式表放在常规样式表之后就可以了。如果您这样做并且您的 IE 表没有被接受,那么您可能需要编写更具体的选择器。
而不是...
或
If you are using the same selectors in both stylesheets then you should be fine as long as you place the conditional IE stylesheet after the regular stylesheet. If you do that and your IE sheet isn't taking then you might need to write more specific selectors.
instead of...
or
不要忘记,您还可以使用
!important
规则来覆盖 CSS 定义。 这里是有关该规则的 W3C 文档。Don't forget that you can also use the
!important
rule to override CSS definitions. Here is the W3C documentation on that rule.也许您可以重新组织样式表以默认为 IE 样式,并使用
if !IE
条件来覆盖“良好的浏览器”。Perhaps you can reorganize the stylesheets to default to IE styles and use an
if !IE
conditional for "good browser" overrides.根据我自己对类似问题的经验,我猜测 IEonly.css 文件中潜伏着一些错误或丢失的字符。追踪它们可能非常痛苦,因此请执行以下操作:
您还可以尝试阅读 http://www.w3.org/TR /CSS2/cascade.html#important-rules 了解更多信息。
您能发布一些代码供我们查看吗?那会有帮助的。
Based on my own experience of similar problems I would guess that there are some bad or missing character lurking somewhere in your IEonly.css file. They can be a real pain to track down, so do the following:
You can also try reading http://www.w3.org/TR/CSS2/cascade.html#important-rules for more information.
Can you publish some code for us to look at? That would help.
我向该元素添加了一个类,并在带有类选择器的 IEonly 样式表和不带类选择器的常规样式表上引用了它。这导致 IEonly 样式声明覆盖常规样式声明。
I added a class to the element and referenced it on the IEonly stylesheet with the class selector and the regular style sheet without. This caused the IEonly style declaration to override the regular one.