Tywele Tywele - 1 year ago 101
CSS Question

How to select the last element within an element regardless of type in CSS?

I want to select the last nested element regardless of the element's type.


<div></div> <-- I want this element
<a></a> <-- I want this element
<ul> <-- I want this element

How do I get these elements?
doesn't seem to do the trick and
is also not helpful because I have to specify which type of element I want.

I want the last nested element of the

Answer Source

Use this:

section > *:last-child {
    // your custom css styles


This works because when you use:

> it select the immediate children

* this selects all the the elements

nth-child ensures that all the immediate children will be targetted (if you use nth-of-type that is not the case.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download