CSSの役割:最初の子セレクター
CSS:first-childセレクターを使用して、親の最初の子であるすべての
要素のスタイルを設定します。
例
次のコードを実行して、:first-childセレクターを実装してみてください
<!DOCTYPE html>
<html>
<head>
<style>
p:first-child {
background-color: orange;
}
</style>
</head>
<body>
<h1>Heading</h1>
<p>This is demo text.</p>
<div>
<p>This is demo text, with the first child of its parent div.</p>
<p>This is demo text, but not the first child.</p>
</div>
</body>
</html> -
CSSの役割:nth-last-of-type(n)セレクター
CSS:nth-last-of-type(n)セレクターを使用して、最後の子から数えて、親の2番目の要素であるすべての要素を選択します。 例 次のコードを実行して、:nth-last-of-type(n)セレクターを実装してみてください。 <!DOCTYPE html> <html> <head> <style> p:nth-last-of-type(2) {
-
CSSの役割:nth-last-child(n)セレクター
CSS:nth-last-child(n)セレクターを使用して、最後の子から数えて、親の子であるすべての要素のスタイルを設定します。 次のコードを実行して、:nth-last-child(n)セレクター-を実装してみてください。 例 <!DOCTYPE html> <html> <head> <style> p:nth-last-child(4) {