【发布时间】:2026-02-23 07:50:02
【问题描述】:
是否可以使用 CSS3 选择器 :first-of-type 来选择具有给定类名的第一个元素?我的测试没有成功,所以我认为它不是?
守则 (http://jsfiddle.net/YWY4L/):
p:first-of-type {color:blue}
p.myclass1:first-of-type {color:red}
.myclass2:first-of-type {color:green}
<div>
<div>This text should appear as normal</div>
<p>This text should be blue.</p>
<p class="myclass1">This text should appear red.</p>
<p class="myclass2">This text should appear green.</p>
</div>
【问题讨论】:
-
这能回答你的问题吗? CSS selector for first element with class
标签: css css-selectors