【发布时间】:2023-03-25 19:15:02
【问题描述】:
我有 4 段 <p>。除了将前两段保留在此结构上之外,我需要选择所有段落:
<div class="right">
<a></a>
<p>heading</p>
<p></p>
<p style="margin-bottom:6.0pt;vertical-align:baseline;">
<span style="color:#2F2F2F ;">hi....Each day the world meets your expectations. It's no secret that your perspective shapes your experience.
What's remarkable, however, is how belief builds awareness; and how with every insight, doors open, new futures unfold
and once-only-dreamed-of possibilities become everyday realities.</span>
</p>
<p style="margin-bottom:6.0pt;vertical-align:baseline;">
<span style="color:#2F2F2F ;">Each day the world meets your expectations. It's no secret that your perspective shapes your experience.
What's remarkable, however, is how belief builds awareness; and how with every insight, doors open, new futures unfold
and once-only-dreamed-of possibilities become everyday realities.</span>
</p>
<p style="margin-bottom:6.0pt;vertical-align:baseline;">
<span style="color:#2F2F2F ;">Each day the world meets your expectations. It's no secret that your perspective shapes your experience.
What's remarkable, however, is how belief builds awareness; and how with every insight, doors open, new futures unfold
and once-only-dreamed-of possibilities become everyday realities.</span>
</p>
</div>
我在css下面写了,
.right p:not(:nth-child(4)){
background:yellow;
}
但它只选择第一、第三和第四。
但我们只需要第三和第四,而不是第一和第二
如何做到这一点?
【问题讨论】:
-
:nth-child(2n + 6) -
试试
p:nth-child(n+3) -
试试
div > p ~ p ~ p { ... } -
你能添加你元素的真实标记吗?
标签: javascript html css css-selectors