Zebra striping a table with hidden rows using CSS3?

后端 未结 9 2321
滥情空心
滥情空心 2020-12-01 20:49

I\'ve got a table

 
&
9条回答
  •  生来不讨喜
    2020-12-01 21:18

    For a jquery way, you could use this function which iterates through the rows in your table, checking the visbility of the row and (re)setting a class for visible odd rows.

        function updateStriping(jquerySelector) {
            var count = 0;
            $(jquerySelector).each(function (index, row) {
                $(row).removeClass('odd');
                if ($(row).is(":visible")) {
                    if (count % 2 == 1) { //odd row
                        $(row).addClass('odd');
                    }
                    count++;
                }            
            });
        }
    

    Use css to set a background for odd rows.

    #mytable tr.odd { background: rgba(0,0,0,.1); }
    

    Then you can call this zebra-striper whenever by using:

    updateStriping("#mytable tr");
    

提交回复
热议问题