div inside ul prevents selecting first child li selector

Issue

I am working in a CMS. first-child selector not working as there is a div inside the ul. When i remove the div in console, first-child selector applies. I cant change the DOM nor use JS. So what would be the solution. Thanks in advance.

ul.tab-list li:first-child img{
     max-width: 145px;
     height: 59px;
}
<ul class="tab-list">
  <div></div>
  <li class=" tab-list-element">
    <a href="#">
      <img src="Logo.png" alt="Logo">
    </a>
  </li>
  <div></div>
  <li class=" tab-list-element">
    <a href="#">
      Link Text
    </a>
  </li>
</ul>

Solution

To select the <img> inside the <li> that is the subsequent sibling of the <div> that is the first child of a <ul>:

ul > div:first-child + li img {
  // ...
}

Answered By – kmoser

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published