首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >变化的特异性

变化的特异性
EN

Stack Overflow用户
提问于 2012-08-05 16:23:35
回答 1查看 93关注 0票数 0
代码语言:javascript
复制
<html>
  <head>
    <style type="text/css">
    #sidebar p {
        font-family: Verdana;
        font-size: .9em; }

        #sidebar .intro {
            font-family: Georgia;
            font-size: 1.25em;
            color:red;
            }

    </style>

  </head>
  <body>
    <div id=”sidebar”>
       <p class=”intro”>
           As you can see, the more CSS styles you create, the greater the potential for formatting
          snafus. For example, you may create a class style specifying a particular
         font and font size, but when you apply the style to a paragraph, nothing happens!
          This kind of problem is usually related to the cascade. Even though you may think
         that directly applying a class to a tag should apply the class’s formatting properties,
          it may not if there’s a style with greater specificity.

        You have a couple of options for dealing with this kind of problem. First, you can
        use !important (as described in the box above) to make sure a property always
        applies. The !important approach is a bit heavy handed, though, since it’s hard to
        predict that you’ll never, ever, want to overrule an !important property someday.
        Read on for two other cascade-tweaking solutions.
    </p>    
</div>

  </body>
</html>

#侧栏p样式的特异性为101 ( ID为100,标签选择器为1),而.intro style的特异性为10 (类选择器为10点)。由于101大于10,所以#侧栏p优先。将.intro改为#侧栏.intro将其特异性更改为110。

即使我改变了这一点,我的结果也不会到来

有人能解释我。

输出:应该是红色,字体大小-1.25em和字体系列-Georgia。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-05 16:38:14

ID sidebar和类名intro周围的引号无效。”sidebar”应该是"sidebar"

浏览器将ID解释为”sidebar”,而不是sidebar,因此,您的规则甚至都不匹配。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11818047

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档