html - #id h1, h2, h3 { } 被之前的 #id h1, h2, h3 { } 覆盖

标签 html css

我有这个 .css 来控制不同 div 内的 h1 h2 和 h3s。

  #about h1, h2, h3{
  font-family: 'Noto Serif', serif;
  font-style: italic;
  color: #797979;
}


#consult h3{
  color: #797979;
  margin-top: 59px;
  margin-bottom: 31px;
}

我有两个不同的 div,一个是#consult,另一个是#about。

但是,#consult h3 是否继承了#about h3 的所有内容?

最佳答案

选择器字符串中的逗号 (#about h1, h2, h3) 完全破坏了选择器。例如,您首先使用 CSS 规则;

#about h1, h2, h3{
    font-family: 'Noto Serif', serif;
    font-style: italic;
    color: #797979;
}

与此相同;

#about h1 {
    font-family: 'Noto Serif', serif;
    font-style: italic;
    color: #797979;
}
h2 {
    font-family: 'Noto Serif', serif;
    font-style: italic;
    color: #797979;
}
h3 {
    font-family: 'Noto Serif', serif;
    font-style: italic;
    color: #797979;
}

你真正想要的是这个;

#about h1, #about h2, #about h3{
    font-family: 'Noto Serif', serif;
    font-style: italic;
    color: #797979;
}

相当于这个;

#about h1 {
    font-family: 'Noto Serif', serif;
    font-style: italic;
    color: #797979;
}
#about h2 {
    font-family: 'Noto Serif', serif;
    font-style: italic;
    color: #797979;
}
#about h3 {
    font-family: 'Noto Serif', serif;
    font-style: italic;
    color: #797979;
}

关于html - #id h1, h2, h3 { } 被之前的 #id h1, h2, h3 { } 覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23880979/

相关文章:

javascript - CSS 缩放属性破坏字体的外观

javascript - jQuery 不是同时动画 div

javascript - Owl Carousel v1.3.2 带垂直滑动动画

javascript - .attr.replace() 在 javascript 中不起作用

html - jade - 创建多个 html 元素

html - 如何在 100% 宽度包装器内居中 float 、多行 div?

html - 溢出-x :hidden "cuts-off" dropdown

javascript - HTML/CSS - 基于浏览器大小的 float 图像

javascript - 使用拖放 HTML 上传图片

html - 仅当元素堆叠时如何设置媒体查询