如何在从循环中打印时定义last-child


How to define last-child when printing from a loop?

我使用PHP for循环来打印一些投资组合项目,这与以下内容相呼应:

echo "
         <a href='"portfoliodetail.php?id=$id'" class='"noHover'" title='"$title'">
         <img src='"images/portfolio/thumbnails/$bgthumbnail'" alt='"$title'" />
        </a>
";

但是,我重复了三次图像,并且我希望最后一个图像与其他图像具有不同的边距。

所以我想我只是在CSS中定义一个:last-child,但是当我把这个边距设为0时,所有的边距都被设为0。也许在循环中重复this时,它认为所有的项都是last-child之类的?有没有办法使最后一张图片的边距不同?

使用CSS,您可以使用:last-child属性设置空白

<style>
    div a img{margin-left:10px;}
    div a:last-child img{margin-left:50px;}
</style>
<div>
    <a href="#" class="noHover" title=""><img src="http://www.iwebsource.net/wp-content/uploads/2012/02/css3.png" /></a>
    <a href="#" class="noHover" title=""><img src="http://www.iwebsource.net/wp-content/uploads/2012/02/css3.png" /></a>
    <a href="#" class="noHover" title=""><img src="http://www.iwebsource.net/wp-content/uploads/2012/02/css3.png" /></a>
</div>

小提琴示例