我有两个 css 样式,我只想在第一个存在时使第二个生效。我该怎么做?我知道您可以向类标签添加多个类,但以相同的方式嵌套 css 标签似乎不起作用。
.stat{float: left; width: 200px; height: 40px; padding: 5px; margin: 5px; border: 1px solid #000;}
.stat .red{background-color: #c00;}
<!-- This should have the background color -->
<div class="stat red">
<!-- This should not have the background color -->
<div class="red">
<!-- This should not have the background color -->
<div class="stat">
最佳答案
只留下空格:
.stat.red{background-color: #c00;}
关于html - 同一类标签上的 CSS 嵌套规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14284134/