It's not possible to select the element based on its contents using CSS. There simply is no selector for that.
If you're not looking at the content, you can still differentiate between the two elements, by checking where they are in their parent, or where they are related to other elements.
Children of their parent
For instance, you can use :first-child
, or the more generic :nth-child(x)
to get a specific child, so .Test:first-child
will select only the .Test div that is the first child of its parent. It won't select the other one.
.Test:first-child {
border: 1px solid blue;
}
.Test:nth-child(2) {
border: 5px solid red;
}
<div tabindex="0" class="Test" role="button"> == $0</div>
<div tabindex="0" class="Test" role="button"></div>
Looking at their siblings
Alternatively, you can use the ~
combinator to look for siblings:
.Test {
border: 1px solid blue;
}
/* A .Test that is following another .Test */
.Test ~ .Test {
border: 5px solid red;
}
<div tabindex="0" class="Test" role="button"> == $0</div>
<div tabindex="0" class="Test" role="button"></div>