细节
我在使用FirefoxDeveloperEdition时遇到了意想不到的选择器优先级问题。我阅读了Smashing Magazine文章 "CSS Specificity: Things You Should Know" ,据我所知,已经按照应有的规则为每个CSS选择器构建了特定级别的优先级。然而,错误的声明被取消了。
问题出在哪里?是我对选择器特异性的工作原理没有完全掌握吗?这是一个bug吗?还是其他什么原因?
项目代码(简化版)
/index.html
<head>
<link href="css/style.css">
</head>
<body>
<section class="hud">
<section class="main float-l">
<a href="#0" class="button">
<div class="outer container">
<div class="inner container">
<p class="show"> <!-- This text is meant to be white by the style declared at line 159. But, it's grey by line 61. -->
View Details
</p>
<div class="arrow"></div>
<p class="hide"> <!-- This text is meant to be white by the style declared at line 159. But, it's grey by line 61. -->
Hide Details
</p>
</div>
</div>
</a>
</section>
</section>
</body>
/css/style.css
58 .hud > .main p /* I also tried `.hud > .main p:not(.button)` */
59 {
60 vertical-align: middle;
61 color: #7C7C7C; /* This grey is applied of the white of line 159. */
62 {
...
155 .hud > .main > .button
156 {
157 display: block;
158 background-color: #986B99;
159 color: #FFFFFF; /* This white should be applied, but is overridden by the grey of line 61. */
160 height: 36px;
161 margin: 20px 10px 10px;
162 padding: 8px 20px;
163 font-weight: 400;
164 text-decoration: none;
165 text-transform: uppercase;
166 border-radius: 2px;
167 }
检查器
尝试使用.hud > .main > .button
与.hud > .main p
进行比较
还尝试使用.hud > .main > .button
与.hud > .main p:not(.botton)
进行比较
p:not(.button)
,并期望这会改变他的按钮颜色? - Chadp
是.button
的后代而不是子元素,那么在.hud > .main p:not(.button)
中,p
之间有a
和.main
,这会有什么影响呢? - tjfwalker