change color of rows in a table in HTML and CSS

后端 未结 6 696
天命终不由人
天命终不由人 2021-01-19 22:25

Trying to learn HTML and CSS and I have a simple question.

How can I give each row a different color in a table? For example row 1 is red, row 2 is blue etc.

6条回答
  •  野性不改
    2021-01-19 22:36

    tr:nth-child(even) {
      background: #ff0101;
    }
    
     tr:nth-child(odd) {
      background: #0030ff;
    }
    Month '94 '95 '96 '97 '98 '99 '00 '01 '02
    Jan 14 13 14 13 14 11 11 11 11
    Feb 13 15 12 15 15 12 14 13 13
    Mar 16 15 14 17 16 15 14 15 15
    Apr 17 16 17 17 17 15 15 16 16
    May 21 20 20 21 22 20 21 20 19
    Jun 24 23 25 24 25 23 25 23 24
    Jul 29 28 26 26 27 26 25 26 25
    Aug 29 28 27 28 28 27 26 28 26
    Sep 24 23 23 26 24 24 24 22 21
    Oct 20 22 20 22 20 19 20 22
    Nov 18 17 16 17 16 15 14 15
    Dec 15 13 13 14 13 10 13 11

提交回复
热议问题