Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: How to say .class:last-of-type [classes, not elements!] [duplicate]

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 ?

like image 329
Sliq Avatar asked Nov 03 '12 17:11

Sliq


People also ask

How do you select the last class in CSS?

To select the last element of a specific class, you can use the CSS :last-of-type pseudo-class.

Does last-of-type work with classes?

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.

How do you not get the last element in CSS?

The :not() selector excludes the element passed to it from selection. The :last-child selector selects the last child.

How do you select all but last element in CSS?

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.


1 Answers

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.

like image 106
amustill Avatar answered Sep 28 '22 10:09

amustill