Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 使用css在表中选择奇数行和特定单元格的有效方法_Html_Css - Fatal编程技术网

Html 使用css在表中选择奇数行和特定单元格的有效方法

Html 使用css在表中选择奇数行和特定单元格的有效方法,html,css,Html,Css,我有以下示例表: <table id="inputTable"> <thead> <tr> <th>Id</th> <th>Name</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>Mike</

我有以下示例表:

<table id="inputTable">
  <thead>
    <tr>
      <th>Id</th>
      <th>Name</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>Mike</td>
    </tr>
    <tr>
      <td>2</td>
      <td>eric</td>
    </tr>
    <tr>
      <td>3</td>
      <td>jonas</td>
    </tr>
  </tbody>
</table>

但它不起作用。有人有办法吗

你的CSS不工作是因为它的目标是
#mainTable
,但是你的HTML说
id=“inputable”
你的CSS不工作是因为它的目标是
#mainTable
,但是你的HTML说
id=“inputable”
tr:n个孩子(奇数)td:n个孩子(2){
背景色:红色;
}

身份证件
名称
1.
迈克
2.
埃里克
3.
乔纳斯
tr:n个孩子(奇数)td:n个孩子(2){
背景色:红色;
}

身份证件
名称
1.
迈克
2.
埃里克
3.
乔纳斯

尝试使用css进行奇偶选择

tr:nth-child(even) {background: #CCC}
tr:nth-child(odd) {background: #FFF}

尝试使用css进行奇偶选择

tr:nth-child(even) {background: #CCC}
tr:nth-child(odd) {background: #FFF}

可能是因为表格上指定的id在您使用#mainTable的CSS中是可输入的。可能是因为表格上指定的id在您使用#mainTable的CSS中是可输入的。抱歉,在此处编辑时忘记更改id名称,不是这样的。。我不知道那里出了什么问题。。在另一个html文件上进行了测试,效果良好。可能有参考资料。。无论如何,谢谢Sapologies在这里编辑时忘记更改id名称,不是这样的。。我不知道那里出了什么问题。。在另一个html文件上进行了测试,效果良好。可能有参考资料。。谢谢你