Possible Duplicate:
How do I select the “last child” with a specific class name in CSS?
As the title says, i want to adress css rules to the last element of a certain type which has a certain class. The following code works perfectly:
div:last-of-type { margin-right:0; }
but i want something like
div.class:last-of-type { margin-right:0; }
How to do this ?
To select the last element of a specific class, you can use the CSS :last-of-type pseudo-class.
Yes, using :last-of-type with a class selector alone is very unintuitive; it is best used with a type selector unless you really want the last of any type to have that class.
The :not() selector excludes the element passed to it from selection. The :last-child selector selects the last child.
When designing and developing web applications, sometimes we need to select all the child elements of an element except the last element. To select all the children of an element except the last child, use :not and :last-child pseudo classes.
Unfortunately finding the last .class
is not possible with last-of-type
.
Edit: To actually add something constructive to this answer, you could fallback to JavaScript to locate this selector, or revise your markup/CSS. Whilst I have found myself in the situation that last-of-type
for a class selector would be useful, it's nothing that cannot be worked around with a little more thought.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With