Adding in a CSS element on last item in list

4 posts by 3 authors in: Forums > CMS Builder Community
Last Post: August 24, 2016   (RSS)

By Daryl - August 23, 2016

Hi ciaran_mac,

You can use the end() function to get the last array element then add an if statement inside your foreach loop that checks if the current array's num is equal to the last array element's num. If yes, then add the class.


Daryl Maximo
PHP Programmer -

By Toledoh - August 23, 2016

Try playing around with the css selector of :last-child or :last-of-type.  something like this may work

<ul id="sample">

<?php for each... ?>

<li>Output goes here...</li>

<?php endforeach ?>


- - - -

#sample li:last-of-type { colour: red;}


Tim Forrest

Toledoh Enterprises

By ciaran_mac - August 24, 2016

Thanks Daryl!