:last-child > .custom-class
应该执行您所要求的操作:如果它是最后一个子元素的直接子元素,则选择 custom-class
。
:last-child > .custom-class {
color: green;
}
<div>
<div>
<div class="custom-class">whatever</div>
</div>
<div>
<div class="custom-class">whatever</div>
</div>
<div>
<div class="custom-class">thing i want to select</div>
</div>
</div>