代码之家  ›  专栏  ›  技术社区  ›  forrest

为什么特定的CSS规则不能覆盖一般的CSS规则?

  •  1
  • forrest  · 技术社区  · 15 年前

    作者编辑:很抱歉在这个问题上的混乱。我更改了另一个文件夹的路径,正在读取旧文件!是我的错。谢谢你的帮助。

    我的理解是,如果你把一个特定的规则放在CSS中一个通用规则的下面,那么这个特定的规则应该覆盖这个通用规则。例如,在这个 page

    <body id="inside" class="blog">
    
    <h3><a href="http://dev.extraspecialpatient.com/blog/entry/test-blog-entry/">Test Blog Entry</a></h3>
            <p class="entry-date">published September 13, 2010</p>
            <p>
    This is a test of the American Broadcasting System to see if my entry shows up properly on the website. Summary information goes here.</p>
    <p>Sentence two.</p>
    <p>Sentence three.</p>
    

    body#inside #content p { 
                            margin: 0; 
                            padding: 0 0 20px 20px; 
                            color: #000; 
                            font: 14px/22px "Myriad Pro", Arial, sans-serif; 
                            }
    

    我需要修改段落的填充,并设置日期信息的样式,以便在下面放置以下内容:

    body#inside.blog #content p             { padding: 0 20px 10px 20px; }
    body#inside.blog #content p.entry-date      { 
                                    font-size: 11px; 
                                    color: #4d6b53; 
                                    font-style: italic;
                                    margin: -3px 0 0 20px;
                                    padding: 0;
                                    }   
    

    4 回复  |  直到 15 年前
        1
  •  1
  •   Pekka    15 年前

    我看不到你在上面引用的更具体的规则,也看不到 your CSS file 也不在HTML文档中。我是不是忽略了什么?你可能忘记上传了。

    此外,不必比一般规则更具体:使用

    主体#内部#内容p

    就够了。规则来了 之后 一般规则将足以覆盖它们。

        2
  •  1
  •   mingos    15 年前

    没有 #content HTML中的ID。

        3
  •  1
  •   Shyju    15 年前

    把萤火虫从这里带走 http://getfirebug.com/

        4
  •  0
  •   Tom Smilack    15 年前

    body#inside.blog #content p ,这意味着“p是id为'content'的事物的后代,它是id为'inside'和class为'blog'的主体的后代”

    CSS没有出现,因为body标记中没有id“content”。

    推荐文章