html - 类选择器及其效果

标签 html css

我是 CSS/HTML 的新手,而且我的母语不是英语,所以我在理解类之间的关系时遇到了一些问题。我举个例子:

.classA .classB {
  color: red
}

.classC {
  color: blue
}
<div class="classA">
  <p class="classB classC">
    This text is red
  </p>
</div>

我的问题是:为什么它没有应用 .classC 中定义的样式?

最佳答案

因为 .classA .classB 更具体。然后是.classC

如果你会写:

.classA .classC {color:blue}

然后它会被应用。

有关更多详细信息,您可以查看MDN CSS Specificity

关于html - 类选择器及其效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46449576/

相关文章:

jquery - 如何为选定的日期添加类(class)?

html - 防止移动浏览器显示内容边界之外的元素?

html - 如何为复选框标签添加一致的左边距?

css - div 没有正确并排对齐

python - beautifulsoup - 查找 div 中的所有 li

html - 可靠地使用 hammer.js 获取平移事件,同时仍然在 iOS 中自然滚动......?

html - 高度为 100% 的固定 div 的相等缩进

css - 根据内容宽度将背景颜色应用于宽度

html - 将基线与行内 block 的底部对齐

jquery - ListView 在 jQuery Mobile 的网格系统中显示不正确