简体   繁体   English

css类不应用样式,但id正在应用样式?

[英]css class not applying styling, but id is applying styling?

I have my HTML set up as follows 我的HTML设置如下

<div>
    <ul>
        <li></li>
    </ul>
    <ul>
        <li>
            <a class="nodecoration"></a>
        </li>
    </ul>
</div>

CSS: CSS:

.nodecoration {
    text-decoration:none;
}

When I change my anchor tag to <a id="nodecoration"></a> and change the CSS to: 当我将锚标记更改为<a id="nodecoration"></a>并将CSS更改为:

#nodecoration {
    text-decoration:none;
}

The element now styles. 元素现在样式。 Why is this? 为什么是这样?

Side note: I am also using Twitter Bootstrap, is the CSS from that interfering? 旁注:我也在使用Twitter Bootstrap,是干扰的CSS吗?

This is an indication that another style rule has precedence over that rule. 这表明另一种样式规则优先于该规则。 You may want to make that rule more specific by using a.nodecoration which should increase its precedence. 您可能希望通过使用应该增加其优先级的a.nodecoration来使该规则更具体。

FYI, tools like firebug for Firefox will tell you which rule(s) have the higher precedence. 仅供参考,像firebug for Firefox这样的工具会告诉你哪些规则具有更高的优先级。

bootstrap already have rule for a, you need to be more specific. bootstrap已经有了规则,你需要更具体。

  • tag 1 point 标记1点
  • class 10 points 10分
  • id 100 point id 100点

you may count in this way to know which one is more specific. 你可以用这种方式知道哪一个更具体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM