Here is the sample code.
<div class="main-content">
<div class="some-class">Some Class</div>
<div class="my-class">My Class</div>
<div class="some-other-class"> Some Other Class</div>
<div class="my-class">My Class</div>
</div>
Inside the main content i have class my-class which is not the immediate child of the parent main-content. I want to select the first my-class element. There are two, i need only the first one. I tried :first-child , but that does not work because it is not immediate child , if i remove the some-class element it will work. I also tried :first-of-type, that does not work either.
Is there way in CSS by which i can do that because i have some restrictions i.e
- I can't change the html
- I cannot use javascript or jquery for this , because i don't have access to both of these things.
I have to do it only through CSS. I only have access to CSS.