【发布时间】:2014-12-01 19:59:18
【问题描述】:
我有一个代码每隔一秒就会改变一个 each 的样式。
<?= $k % 2 == 1 ? 'news-figure' : 'news-figure-b' ?>
是否可以为最后的条目设置新样式?
【问题讨论】:
-
你可以这样使用:
li:last-child -
除了
last-child,您还可以使用 CSSnth-of-type消除执行 mod 2 的代码,例如可以使用li:nth-of-type(2n+1) { background-color:red; } li:nth-of-type(2n) { background-color:green; }完成交替颜色的列表项 -
是的,这对我有用,谢谢,我使用了 nth-last-of-type