我正在尝试根据他们的祖先(不是父母,特别是)来设置一些按钮的主题,所以......我有以下 HTML 结构
<body class="theme-a">
<section class="container">
<form class="theme-b">
<div class="button-group">
<button type="button">Button B1</button>
<button type="button">Button B2</button>
</div>
<div class="button-group">
<button type="button">Button B3</button>
<button type="button">Button B4</button>
</div>
</form>
<form>
<div class="button-group">
<button type="button">Button A1</button>
<button type="button">Button A2</button>
</div>
<div class="button-group">
<button type="button">Button A3</button>
<button type="button">Button A4</button>
</div>
</form>
</section>
</body>
好吧,正如你所看到的,有两个主题.theme-a
和.theme-b
CSS 代码如下所示:
.theme-a {
background: #999;
}
.theme-b {
background: #555;
}
.theme-a button {
background: #222;
}
.theme-b button {
background: #69C;
}
问题是:如果您切换主题类(A 与 B,B 与 A),您会注意到 A 主题上的按钮(与主题类有更近的祖先,保持远祖先的样式,蓝色背景而不是黑色背景)。
如何以根据最近的祖先设置按钮属性的方式实现适当的特异性?
这是来自 JSfiddle 的链接:http: //jsfiddle.net/XVaQT/1/
我希望我解释清楚:)
谢谢</p>