CSS选择器找到第一个tbody

Aru*_*hit 3 html css html-table css-selectors

我的HTML代码

<div id="myelement">
    <table class="myclass">
       <tbody>
           <tr>
               <td>something</td>
               <td>
                   <table>
                       <tbody>
                         <tr> hari </tr>
                       </tbody>
                   </table>
               </td>
           </tr>
           <tr>
              foo
           </tr>
       </tbody>
    </table>
</div>
Run Code Online (Sandbox Code Playgroud)

Xpath解决方案

"//tbody[1]"

问题

我正在寻找一个CSS表达式,它应首先选择tbody哪个是直接的孩子table,而不是里面的孩子tr.

如果我使用CSS tbody,那么它将选择2,但我正在寻找一种方法来解决它.我知道table>tbody会工作,我正在寻找是否有更多.在我的情况下,我不能使用table>tbody.

dan*_*l__ 5

 tbody tr td:first-of-type {
     color: red;
 }
Run Code Online (Sandbox Code Playgroud)

DEMO

td:first-of-type 也会有效.


:nth-of-type(1)并且:first-of-type是一样的.文件