Remove leftmost and rightmost padding in LI output


/ Published in: PHP
Save to your folder(s)

Inserts "first" and "last" classes to the first and last items respectively. "first" and "last" classes defined in CSS as without padding.


Copy this code and paste it in your HTML
  1. /*
  2.  * Applies pseudo-pseudo classes to inline list items.
  3.  * Mainly used for autogenerated subnavs.
  4.  *
  5.  * @param $the_list String: html code of <li> elements
  6.  * @param $first Bool: apply style to the first <li>
  7.  * @param $last Bool: apply style to the last <li>
  8.  * @return $the_list String: modified html code
  9.  */
  10. function remove_padding_li ($the_list, $first=FALSE, $last=FALSE)
  11. {
  12. if ($first) {
  13. $the_list = preg_replace('/^<li class=\"/i', '<li class="first ', $the_list);
  14. }
  15. if ($last) {
  16. $the_list = preg_replace('/<li class=\"(.*)$/i', '<li class="last $1', $the_list);
  17. }
  18. return $the_list;
  19. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.