change color of rows in a table in HTML and CSS

后端 未结 6 699
天命终不由人
天命终不由人 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:48

    you can try selecting each row through CSS. In your case:

    table tr:first-child{background:red}    or   table tr:nth-child(1){background:red}
    
    table tr:nth-child(2){background:blue}
    
    table tr:nth-child(3){background:orange}
    
    table tr:nth-child(4){background:yellow}
    
    table tr:last-child{background:purple} or table tr:nth-child(5)
    {background:purple}
    

提交回复
热议问题