Ben Paton Ben Paton - 4 months ago 9
CSS Question

style 2nd element on the page with same class

Hello is there a way with css to style the 2nd element on page with the same class slightly differently to the first.

For example I have two ul's on a page with a class of topbardropdownmenu. I want to give the 2nd ul a differen't background to the first. Is there a way to do this with out altering the html?

Answer

What holds the <ul> elements? I'll assume a <div id = "lists">

/* First element */
div > ul.topbardropdownmenu:first-child{

}

/* Rest of the elements */
div > ul.topbardropdownmenu{

}

...alternatively

div > ul.topbardropdownmenu:not(:first-child)

Comments