table に指定した要素を反映させたいのですが、うまくできません。
指定したtableの中の2番目以降の要素の初めのクラスにそれぞれCSSを反映させるために
下記のコードを指定しました。
/順番指定 2番目以降tbody の中の初めの time class だけ paddingを上に23px 付けたい/
tbody:not(:first-child) .time:first-of-type{
padding-top:23px;
background-color:pink;
}
/順番指定 2番目以降tbody の中の初めの price class だけ paddingを上に23px 付けたい/
tbody:not(:first-child) .price:first-of-type{
padding-top:23px;
background-color:pink;
}
すると、not(:first-child) の指定だけ効いていると思うのですが、
2番目以降の初めの time class だけなく 2番目以降の全ての time class に css が反映されてしまいます。
また、
tbody:not(:first-child) .price:first-of-type
こちらの指定は効いていないように見えます。
どのように直せばよいのでしょうか?
下記がコードにになります。
<table class="menu-list-facial"> <tbody> <tr> <td class="menu" rowspan="4"> <h3 class="parts-title">小顔フェイシャル</h3> </td> </tr> <tr> <td class="time">60分</td><td class="price">¥3,000</td> </tr> <tr> <td class="time">90分</td><td class="price">¥5,000</td> </tr> <tr> <td class="time">120分</td><td class="price">¥7,000</td> </tr> </tbody> <tbody> <tr> <td class="menu" rowspan="3"> <h3 class="parts-title">小顔矯正</h3> </td> </tr> <tr> <td class="time">60分</td><td class="price">¥9,000</td> </tr> <tr> <td class="time">90分</td><td class="price">¥12,000</td> </tr> </tbody> <tbody> <tr> <td class="menu" rowspan="3"> <h3 class="parts-title">プラズマシャワー</h3> </td> </tr> <tr> <td class="time">30分</td><td class="price">¥6,000</td> </tr> <tr> <td class="time">60分</td><td class="price">¥10,000</td> </tr> </tbody> </table>
/*------------------------------------------- menu -------------------------------------------*/ tbody{ border-bottom:1px dotted #000; } #menu .parts .reserve-box{ padding:40px 0; } /*facial*/ .menu-list-facial .menu{ width:80%; padding-bottom:13px; margin-top:20px; vertical-align: top; } .menu-list-facial .time{ width:10%; padding-bottom:13px; margin-top:20px; text-align:right; } .menu-list-facial .price{ width:10%; padding-bottom:13px; margin-top:20px; text-align:right; } /*順番指定 2番目以降tbody の中の初めの time class だけ paddingを上に23px 付けたい*/ tbody:not(:first-child) .time:first-of-type{ padding-top:23px; background-color:pink; } /*順番指定 2番目以降tbody の中の初めの price class だけ paddingを上に23px 付けたい*/ tbody:not(:first-child) .price:first-of-type{ padding-top:23px; background-color:pink; }
試した事、 nth-of-type から nth-child に変更
色をつけて css の反映範囲確認
nthを使わずに 検証ツールから直書き
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/04/26 09:51
2022/04/26 12:21
2022/04/27 01:30 編集
2022/04/27 02:11 編集
2022/04/27 03:56