Zebra striping a table with hidden rows using CSS3?

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

I\'ve got a table

 
&
9条回答
  •  春和景丽
    2020-12-01 21:33

    While you can't Zebra stripe a table with hidden rows using CSS3 you can do it with JavaScript. Here is how:

        var table = document.getElementById("mytable");
        var k = 0;
        for (var j = 0, row; row = table.rows[j]; j++) {
            if (!(row.style.display === "none")) {
                if (k % 2) {
                    row.style.backgroundColor = "rgba(242,252,244,0.4)";
                } else {
                    row.style.backgroundColor = "rgba(0,0,0,0.0)";
                }
                k++;
            }
        }
    

提交回复
热议问题