Home > front end >  div inside ul prevents selecting first child li selector [duplicate]
div inside ul prevents selecting first child li selector [duplicate]

Time:09-29

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>

CodePudding user response:

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 {
  // ...
}
  • Related