【发布时间】:2017-06-27 22:07:28
【问题描述】:
如何选择下面最后一个has-errors div?
<section class="form-block">
<div class="form-group has-errors">
ERROR!
</div>
<div class="form-group has-errors">
ERROR!
</div>
<div class="form-group">
stuff
</div>
</section>
我可以选择第一个 has-errors 使用:
.form-block .form-group.has-errors:first-child {
background-color: blue;
}
但是last-child 在上面不起作用。如何选择.form-group.has-errors 的最后一个实例?
【问题讨论】:
-
解决方案与上面链接的问题有很大不同。链接答案中的解决方案不适用于我的用例。下面的答案是适用于我的问题的方法。
标签: html css selector children