「CSS」nth-of-type指定した行にCSSを適用する
環境
Google Chrome 102.0.5005.63
Windows 10 64bit
書式
tr:nth-of-type(数字){属性:値}
nth-of-typeを利用して、指定した行のCSSを適用します。
使用例
<!DOCTYPE html>
<html>
<head>
<style>
tr:nth-of-type(4){
background-color: red;
font-size:20px;
}
</style>
<table>
<tr><td>東京</td></tr>
<tr><td>大阪</td></tr>
<tr><td>福岡</td></tr>
<tr><td>横浜</td></tr>
</table>
</body>
</html>
結果
4行目の背景色と文字サイズが変わります