Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2023/07-01——解除对 :last-of-type 的误会 #157

Open
HannibalKcc opened this issue Jul 8, 2023 · 0 comments
Open

2023/07-01——解除对 :last-of-type 的误会 #157

HannibalKcc opened this issue Jul 8, 2023 · 0 comments

Comments

@HannibalKcc
Copy link
Owner

HannibalKcc commented Jul 8, 2023

css 选择器中 :last-of-type,我几乎没有使用过。最近有人问相关问题,确实是刷新了我对这个选择器的认知。

type 指的是元素的标签类型,与前缀没有关系。比如

<div>
  <p class="foo">1</p>
  <p class="foo">1</p>
  <p class="foo">1</p>
  <p>命中</p>
  <button>2</button>
  <button class="foo">命中</button>
<div>
// 先按照 div .foo 找到所有命中的元素,查看它们的标签类型,然后选择兄弟组件里最后一个相同类型的标签
// 如果命中的元素有多种标签类型,那么会选中个标签,具体可以看 MDN example
div .foo:last-of-type {
 background-color: red;
}

MDN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant