Exclusion through php and problems with :last-child



  • <div class="katalog">
    <p>Каталог</p>
        <ul>
        <?php foreach($products as $product): ?>
                <a href="#"><li><?=$product['name']?></li></a>
        <?php endforeach;?>
        </ul>
    </div> <!-- /katalog -->
    

    For each element of li, the Borders of the Upper and Lower Border First and Last must be removed, respectively. Through :last-child and :first-child doesn't work out why. Help who can! Thank you in advance!



  • Since there are no details and examples of the code, I'm guessing that the problem is in the vain verb: ul to contain li As a subsidiary, and you have it there. a♪ That's why. :last-child and :first-child You apply to each. li - They don't have a wedding at the same level of investment, which is why each part of the list is both final and first.

    You can replace the correct structure if it suits you:

    <div class="сatalog">
    <p>Каталог</p>
        <ul>
            <?php foreach($products as $product): ?>
                <li><a href="#"><?=$product['name']?></a></li>
            <?php endforeach;?>
        </ul>
    </div>
    

    Either you change thelt and choose the elements. a:last-childa:first-child Because they're daughters for you. ul and at one level of investment. But consider that the references might be somewhere else, so the selter needs to be specific (to get a new one. id or classfor example ul😞

    HTML:

    <ul class="list"> 
        ... 
    </ul>
    

    CSS:

    ul.list a:first-child
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2