I am trying to alter the css on a div
that doesn’t have a unique class name or id and don’t have the ability to give it an id as it is part of a library. This is the layout of the item I am trying to alter.
I am wanting to add some CSS to <div class='thirdClass' />
. Can you use nth-of-type
? I couldn’t get that to work.
<button id='myUsefulBtn'>
<div class='firstClass' />
<div class='secondClass' />
<div class='thirdClass' />
</button>
I was able to get it working with this. Not sure if there is a better way though…
#myUsefulBtn div:nth-child(3) {
color: red;
}
2
Answers
You could use the following to access that div:
Well, to target
<div class='thirdClass' />
without a unique class or ID, you can usenth-child
as valid approach if the structure remains consistent. Meaning, it is the best way if this is the case.