Since there are no details and no sample code, I will assume that the problem is an invalid layout: ul must contain li as children, and you have a there. Therefore :last-child and :first-child are applied to each li - they have no “brothers” at the same nesting level, and therefore each element of the list is both the last and the first.
You can replace with 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>
Or change the selector and select the elements a:last-child , a:first-child since they are children of ul and are on the same nesting level. But keep in mind that links can be somewhere else, because the selector must be somehow specified (add a new id or class , for example, for ul ):
HTML:
<ul class="list"> ... </ul>
CSS:
ul.list a:first-child