【问题标题】:Confusing CSS - can anyone explain [duplicate]令人困惑的CSS - 任何人都可以解释[重复]
【发布时间】:2019-05-26 23:58:00
【问题描述】:

我知道 css 中的点是类,但是我在页面中找到的以下内容中应该选择的 h2h1 是什么?

h1 {
  font-size: 30px;
  line-height: 32px;
}
h2.h1 {
  font-size: 36px;
  line-height: 40px;
}
.title.title_size_medium h1 {
  font-size: 38px;
  line-height: 38px;
}

h1 标签本身从未在页面中使用。

非常感谢

【问题讨论】:

  • 这意味着选择带有.h1类的h2标签。如果.h1 类从未使用过,则不会被选中。

标签: css


【解决方案1】:

h2.h1 正在选择一个 h2 元素,其类为 h1

h1 {
  font-size: 30px;
  line-height: 32px;
  color: red;
}

h2.h1 {
  font-size: 36px;
  line-height: 40px;
  color: blue;
}

.title.title_size_medium h1 {
  font-size: 38px;
  line-height: 38px;
  color: grey;
}
<h1>Just an h1 element</h1>
<h2 class="h1">h2 element with the class "h1"</h2>

<div class="title title_size_medium">
  <h1>An h1 element inside a div with the class "title" and "title_size_medium"</h1>
</div>

【讨论】:

    【解决方案2】:

    h2.h1 在您的 html 中选择 &lt;h2&gt; 标签,.h1 css 类使用 h2 css 类中的样式设置 h2 标签的样式。

    【讨论】:

      猜你喜欢
      • 2020-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-31
      • 2013-03-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多