css 中 first-of-type 与 first-child 的区别

发布时间: 2019-09-21 11:12:07 作者: 大象笔记

举个直观的例子:

<div class="main">
  <h1>Languages</h1>   <!-- h1:first-child, h1:first-of-type -->
  <div>Javascript</div>   <!-- div:nth-child(2), div:first-of-type -->
  <div>Golang</div>
  <div>PHP</div>
</div>

例如:

<div>Javascript</div>

是 div:first-of-type,但是不是 div:first-child.

我是一名山东烟台的开发者,联系作者