Alternate background colors for list items

前端 未结 9 1841
一向
一向 2020-12-04 07:42

I have a list, and each item is linked, is there a way I can alternate the background colors for each item?

9条回答
  •  不思量自难忘°
    2020-12-04 08:35

    You can achieve this by adding alternating style classes to each list item

    
    

    And then styling it like

    li { backgorund:white; }
    li.odd { background:silver; }
    

    You can further automate this process with javascript (jQuery example below)

    $(document).ready(function() {
      $('table tbody tr:odd').addClass('odd');
    });
    

提交回复
热议问题