他の要素の中の最初の要素を対象にする必要がありますが、どういうわけか機能しません。対象:first-childまたは:nth-of-type(1)
サイドバーの最初のh2
をターゲットにしたいだけです。
どうすればいいですか?
私はfirst-child
とnth-of-type
で試しましたが、動作しません。
#sidebar h2:first-child {
color: blue;
}
<div id="sidebar">
<div class="right">
<div class="container-right">
<div class="freetext">
<h2>Heading - target me only</h2>
<p>Text</p>
</div>
<div class="freetext">
<h2>Heading</h2>
<p>Text</p>
</div>
</div>
</div>
</div>
ここfiddleを参照してください。
_「と私はちょうどそのサイドバーの最初のH2をターゲットにしたいです。どうしたらいいですか? " - あなたはできません。最低でも_that_だけに基づいています。 nth-fooなどはすべて要素のDOM位置に基づいています。 – CBroe