[問題] Child combinator >

作者: kisha024 (4545454554)   2023-07-04 13:38:51
各位好
https://jsfiddle.net/rxd8eyw1/
如上連結
table > tr {
color: red;
}
<table>
<tr>
<th></th>
<th scope="col">國文</th>
<th scope="col">英文</th>
<th scope="col">數學</th>
</tr>
<tr>
<th scope="row">張三</th>
<td>78</td>
<td>60</td>
<td>98</td>
</tr>
<tr>
<th scope="row">李四</th>
<td>67</td>
<td>65</td>
<td>85</td>
</tr>
<tr>
<th scope="row">王五</th>
<td>69</td>
<td>85</td>
<td>45</td>
</tr>
</table>
https://developer.mozilla.org/en-US/docs/Web/CSS/Child_combinator
在HTML的結構上 tr 應該是 table 的 direct child 吧
但 table > tr 這樣寫,好像沒 match 到 tr
我知道可以用 table tr, 但為什麼 table > tr 不行呢?
謝謝
作者: nick8195 (煎餅)   2023-07-04 13:46:00
雖然html當中沒有使用,但結構上table底下還有tbody改成table>tbody>tr就能達到效果了
作者: qptw (老魚兒)   2023-07-04 15:02:00
>是子代,也就是TABLE裡面第一子層必須是TR,而空格則是後代的概念,TABLE 裡面可以隔著別人,只要找到TR就可以了
作者: microloft (微閣)   2023-07-04 15:28:00
承1樓,就算你沒寫tbody,瀏覽器還是會自動幫你加
作者: nottt (無)   2023-07-04 16:32:00
https://i.imgur.com/gyjgenB.png 不要相信自己的原始碼以瀏覽器渲染出來的為主,因為可能被js或其他外掛更換html

Links booklink

Contact Us: admin [ a t ] ucptt.com