即使元素嵌套在 div 中,我如何设置 :nth-child(4n)
样式,这里的示例是 p
div
:
p:nth-child(2) {
background: red;
}
<p>The first paragraph.</p>
<div>
<p>The second paragraph.</p>
</div>
<p>The third paragraph.</p>
<p>The fourth paragraph.</p>
最佳答案
body p:nth-child(2n) {
background: red;
}
body div:nth-child(2n) p {
background: red;
}
<body>
<p>The first paragraph.</p>
<div>
<p>The second paragraph.</p>
</div>
<p>The third paragraph.</p>
<p>The fourth paragraph.</p>
<body>
关于html - CSS 样式 :nth-child even nested elements,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43607712/