Tywele Tywele - 1 month ago 6x
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


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.