私は初心者のhtmlです。 「スタイル」タグと「p」タグの間にタグを置くと、コードが機能しないのはなぜですか?擬似クラスが動作していません
p:first-child {
color: red;
}
<h1>example</h1>
<!-- problem is here -->
<p>Hello venus</p>
<p>hello world</p>
私は初心者のhtmlです。 「スタイル」タグと「p」タグの間にタグを置くと、コードが機能しないのはなぜですか?擬似クラスが動作していません
p:first-child {
color: red;
}
<h1>example</h1>
<!-- problem is here -->
<p>Hello venus</p>
<p>hello world</p>
必要があるかもしれません。
p:first-of-type{
color:red;
}
<h1>example</h1> <!-- problem is here -->
<p>Hello venus</p>
<p>hello world</p>
First-child
段落の最初の、ちょうど最初の子ではありません。
:first-child {color:red;}
div h1:first-child {color: green;}
div p:first-child {color: blue} /* match nothing */
<h1>example</h1> <!-- problem is here -->
<p>Hello venus</p>
<p>hello world</p>
<div>
<h1>example</h1> <!-- problem is here -->
<p>Hello venus</p>
<p>hello world</p>
</div>
p:first-child
体の最初の子を狙っています。あなたは、あなたがfirst-of-type
を使用する必要がp:first-of-type
p:first-of-type {
color: red;
}
<h1>example</h1>
<!-- problem is here -->
<p>Hello venus</p>
<p>hello world</p>
それは、任意の要素の最初の子である何の要素 `p`はありません:first-of-type
セレクタ
p:first-of-type{
color:red;
}
<h1>example</h1> <!-- problem is here -->
<p>Hello venus</p>
<p>hello world</p>
を使用することをお勧めします。最初の子はここで 'h1'です。 – panther
あなたは既にあなたのコードで問題を指摘しています... –