为什么我的 !important 属性在 Google Chrome 中不起作用?

发布于 2024-09-09 07:49:40 字数 1918 浏览 4 评论 0原文

我的网络应用程序中有两个 CSS 文件:reset.css 和 screen.css。它们按该顺序出现在 html 中(重置然后屏幕)。

在reset.css中,出现以下样式定义:

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
  border-bottom-width:0;
  border-color:initial;
  border-left-width:0;
  border-right-width:0;
  border-style:initial;
  border-top-width:0;
  font-family:inherit;
  font-size:100%;
  font-style:inherit;
  font-weight:inherit;
  margin-bottom:0;
  margin-left:0;
  margin-right:0;
  margin-top:0;
  outline-color:initial;
  outline-style:initial;
  outline-width:0;
  padding-bottom:0;
  padding-left:0;
  padding-right:0;
  padding-top:0;
  vertical-align:baseline;
}

您可以看到span在此列表中,并且默认情况下font-size为100%。

在我的 screen.css 中,我有以下内容:

dl.labels-left dt span.req {
  display:inline;
  font-size:14px !important;
}

我的 HTML 有以下摘录:

<div>
    <dl class="labels-left">
        <dt class="larger-a-left">
            <label>Name:</label>
            <span class="req">*</span>
        </dt>
...

我遇到的问题是 font-size: 14px !important; 被中的 CSS 覆盖重置文件,但仅限于 Google Chrome。我不明白为什么!

下面是 Firebug Lite 屏幕截图,显示了被划掉的 font-sizeFirebug 屏幕截图 http://www.damianbrady.com.au/images/firebug_screenshot.png

为什么我的reset.css样式被认为比具体的类定义更重要?

根据我对W3C CSS 2.1 特异性,这不应该发生!

I have two CSS files in my web app: reset.css and screen.css. They appear in that order in the html (reset then screen).

In the reset.css, the following style definition occurs:

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
  border-bottom-width:0;
  border-color:initial;
  border-left-width:0;
  border-right-width:0;
  border-style:initial;
  border-top-width:0;
  font-family:inherit;
  font-size:100%;
  font-style:inherit;
  font-weight:inherit;
  margin-bottom:0;
  margin-left:0;
  margin-right:0;
  margin-top:0;
  outline-color:initial;
  outline-style:initial;
  outline-width:0;
  padding-bottom:0;
  padding-left:0;
  padding-right:0;
  padding-top:0;
  vertical-align:baseline;
}

You can see that span is in this list, and by default has a font-size of 100%.

In my screen.css, I have the following:

dl.labels-left dt span.req {
  display:inline;
  font-size:14px !important;
}

My HTML has the following excerpt:

<div>
    <dl class="labels-left">
        <dt class="larger-a-left">
            <label>Name:</label>
            <span class="req">*</span>
        </dt>
...

The problem I'm having is that the font-size: 14px !important; is being overridden by the CSS in the reset file, but only in Google Chrome. I can't work out why!

Here's a Firebug Lite screenshot showing the font-size crossed out:
Firebug Screenshot http://www.damianbrady.com.au/images/firebug_screenshot.png

Why is my reset.css style being considered more important than the specific class definition?

According to my understanding of W3C CSS 2.1 Specificity, this shouldn't happen!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那片花海 2024-09-16 07:49:40

也许检查员错误地划掉了它,但从视觉上看是正确的?

Maybe the inspector is crossing it out improperly but visually it's right?

月依秋水 2024-09-16 07:49:40

这是一个 Firebug Lite 错误。 Firebug Lite 正在总结规则中定义的每个选择器的特异性值(而不仅仅是 CSS 规范中所说的匹配的选择器),因此它会导致值被高估。

我刚刚为此填写了一份问题报告。如果您想收到有关我们解决此特定问题的进展的电子邮件更新,请“星标”(订阅)该问题:

http://code.google.com/p/fbug/issues/detail?id=3262

另外,下次对于 Firebug / Firebug Lite 问题,请尝试使用我们的讨论列表或我们的错误跟踪。否则我们可能意识不到这个问题。

顺便感谢您的详细报告!

It is a Firebug Lite bug. Firebug Lite is summing up the specificity value of each selector defined in the rule (and not only the matched ones like the CSS specification says), so it is resulting in a overestimated value.

I just filled an issue report for it. Please "star" (subscribe) the issue if you want to receive email updates about our progress with this particular problem:

http://code.google.com/p/fbug/issues/detail?id=3262

Also, next time, for Firebug / Firebug Lite issues, try using our discussion list or our bug tracking. Otherwise we may not be aware of the problem.

Thanks for the detailed report by the way!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文