要使用 CSS 為作為其父級的第二個子級的每個
元素設置樣式,請使用 CSS :nth-child(n) 選擇器。
示例 h2>
您可以嘗試運行以下代碼來實現:nth-child(n)選擇器
Live Demo
<!DOCTYPE html>
<html>
<head>
<style>
p:nth-child(4) {
background: orange;
color: white;
}
</style>
</head>
<body>
<p>This is demo text 1.</p>
<p>This is demo text 2.</p>
<p>This is demo text 3.</p>
<p>This is demo text 4.</p>
<p>This is demo text 5.</p>
<p>This is demo text 6.</p>
</body>
</html>
登錄后復制
以上就是使用 CSS 為作為其父級的第二個子級的每個元素設置樣式的詳細內容,更多請關注www.92cms.cn其它相關文章!






