CSS中是否有方法定位p
之前的每个div.carrots
?在这种情况下,我们会得到 Munch 但不会 Burp 。
<p>Munch Munch!</p>
<div class="carrots">
</div>
<p>Burp!</p>
<div class="potatoes">
</div>
答案 0 :(得分:0)
没有“上一个兄弟”选择器。只有adjacent and general combinators,要求目标兄弟在之后 。
为了在这种情况下选择<p>
,您可以使用某个元素(例如.container
并使用.container p:first-child
作为选择器来包围内容。我认为事情不会如果你这样做,那就完全不同了:
<div class=carrots>
<p>Munch Munch!</p>
<div>
</div>
</div>