0

This is similar to this question, however I want to know if I can do same with css only.

My code:

.a:last-of-type {
  background: #ff0000;
}
<h1>This is a heading</h1>
<p class="a">The first paragraph.</p>
<p class="a">The second paragraph.</p>
<p class="a">The third paragraph.</p>
<p class="a">Last of class a, please select.</p>
<p class="b">The fifth paragraph.</p>

So, all I want to do is select the element with the text 'Last of class a, please select', i.e. the last element with class a.

This example has a fixed number of elements, but where I want to use it, the exact number will be set at runtime.

Master.Deep
  • 755
  • 5
  • 18
peterc
  • 5,367
  • 8
  • 53
  • 108
  • In short: What you want is not possible currently in CSS. There's workarounds for this limitation, but each and every one of those has common scenarios in which it will fail. – connexo Feb 17 '22 at 10:50

0 Answers0