Can I color table columns using CSS without coloring individual cells?

前端 未结 8 468
不思量自难忘°
不思量自难忘° 2020-12-12 13:07

Is there a way to color spans of columns all the way down. See, starting example below:

8条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 14:09

    I would use the nth-child css pseudo-class for this:

    tr td:nth-child(2), tr th:nth-child(2), tr td:nth-child(3), tr td:nth-child(4), tr th:nth-child(4), tr td:nth-child(6), tr td:nth-child(7){
        background-color: #DDD;
    }
    

    tr td:nth-child(2),
    tr th:nth-child(2),
    tr td:nth-child(3),
    tr td:nth-child(4),
    tr th:nth-child(4),
    tr td:nth-child(6),
    tr td:nth-child(7) {
      background-color: #DDD;
    }
    Motor Engine Car Body
    1 2 3 4 5 6 7
    7 1 2 3 4 5 6

提交回复
热议问题