:nth-last-of-type

概述

:nth-last-of-type(an+b) 这个 CSS 伪类 匹配那些在它之后有 an+b-1 个相同类型兄弟节点的元素,其中 n 为正值或零值。它基本上和 :nth-of-type 一样,只是它从结尾处反序计数,而不是从开头处。

可以在 :nth-child 中查看关于语法参数更详细的描述。

语法

Error: could not find syntax for this item

Example

HTML

<div>
  <span>This is a span.</span>
  <span>This is another span.</span>
  <em>This is emphasized.</em>
  <span>Wow, this span gets limed!!!</span>
  <strike>This is struck through.</strike>
  <span>Here is one last span.</span>
</div>

CSS

span:nth-last-of-type(2) {
  background-color: lime;
}

Result

规范

Specification
Selectors Level 4
# nth-last-of-type-pseudo

浏览器兼容性

BCD tables only load in the browser

参见