【发布时间】:2023-03-24 11:06:01
【问题描述】:
尝试学习 HTML 和 CSS,我有一个简单的问题。
如何为表格中的每一行赋予不同的颜色?例如第 1 行是红色,第 2 行是蓝色等。
这是我的 HTML 代码:
#table {
font-family: Arial, Helvetica, sans-serif;
width: 600px;
border-collapse;
collapse;
}
#table td,
#table th {
font-size: 12x;
border: 1px solid #4D365B;
padding: 3px 7px 2px 7px;
}
#table th {
font-size: 14px;
text-align: left;
padding-top: px;
padding-bottom: 4px;
background-color: #4D365B;
color: #918CB5;
}
#table td {
color: #000000;
background-color: #979BCA;
}
<table id="table">
<tr>
<th>Company</th>
<th>Contact
<th>Country</th>
</tr>
<tr>
<td>1</td>
<td>2
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2
<td>3</td>
</tr>
<tr>
<td>1</td>
<td>2
<td>3</td>
</tr>
</table>
【问题讨论】:
-
你可以使用 :nth-child(even) 和 :nth-child(odd)