【问题标题】:CSS first-of-type applying to all [duplicate]CSS first-of-type 适用于所有 [重复]
【发布时间】:2018-11-19 06:16:06
【问题描述】:

在使用 CSS :first-of-type 定位 div 并将样式应用于所有内容时遇到一些问题。关于我哪里出错的任何想法?

Working example here

  .message:first-of-type {
      background: purple;
  }

【问题讨论】:

  • 你能在这里分享你的完整代码吗?

标签: html css css-selectors


【解决方案1】:

如果您只想为第一个 .message 使用紫色背景,请在 css 下方使用。 Pseudoclass :first-of-type 仅适用于类型(div、p 等),而不适用于类。

.message {
    background: purple;
}
.message ~ .message {
    background: none;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-04
    • 2014-08-30
    相关资源
    最近更新 更多