背景颜色不适用于显示内容

arp*_*ech 6 css sass react-bootstrap bootstrap-4

我正在尝试将border和添加background-color到我的表中,但它没有被应用。

我的表格的 CSS :-

table {
  width: 100%;
  display: grid;
  overflow: auto;
}
    
table thead,
table tbody,
table tr {
  display: contents;
}
Run Code Online (Sandbox Code Playgroud)

CSS 尝试应用但不起作用

tbody tr:nth-child(odd) { 
  border: solid 1px #e2e2e2;
  background-color: #f4f4f4;
}
tbody tr:nth-child(even) { 
  border: solid 1px #e2e2e2;
  background-color: blue;
}
Run Code Online (Sandbox Code Playgroud)

请建议我一条出路,因为我需要应用background-color. 我也尝试过申请。

tbody tr {
  background-color: blue;
}
Run Code Online (Sandbox Code Playgroud)

这也是行不通的。

提前致谢。

Nik*_*vic 4

尝试选择td

table {
  width: 100%;
  display: grid;
  overflow: auto;
}
tbody tr:nth-child(odd) > td{ 
  border: solid 1px #e2e2e2;
  background-color: #f4f4f4;
}
tbody tr:nth-child(even) > td{ 
  border: solid 1px #e2e2e2;
  background-color: blue;
}
table thead,
table tbody,
table tr {
  display: contents;
 }
Run Code Online (Sandbox Code Playgroud)
<table>
  <thead>
    <tr>
      <th>header</th>
      <th>header</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1st row</td>
      <td>1st row</td>
    </tr>
    <tr>
      <td>2nd row</td>
      <td>2nd row</td>
    </tr>
  </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)