开发者社区> 问答> 正文

有时候不起作用 :first-child

比如下面的代码,不知为什么第一个article的字体不会变色?
html

<h1>logo</h1>
<article>article1</article>
<article>article2</article>
<article>article3</article>

css

article:first-child {
    color: red;
}​

screenshot

展开
收起
杨冬芳 2016-06-14 14:09:41 2177 0
1 条回答
写回答
取消 提交回答
  • 对于 :first-child 这个伪类,规范里是这么定义的:

    The :first-child pseudo-class represents an element that is the first child of some other element.

    到你的选择符上 article:first-child 这意味着这条规则只对article是其它元素的第一个子代的时候生效,你试一下把<h1>logo</h1> 删除,或者移到后面,就会生效

    2019-07-17 19:37:30
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载