https://codepen.io/bazzle/pen/jyWdjM
我想选择第一个p
但不是p
嵌套的内部块引用或任何其他元素。
换句话说,所有孩子p
中的第一个p
但不是孙子p
的<{p>}
<div class="article__body">
<p>
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
</p>
<blockquote>
<p>
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
</p>
</blockquote>
<p>
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
</p>
</div>
CSS(减去)
.article__body{
p:first-of-type{
background-color:green;
}
}
答案 0 :(得分:0)
也许你应该试试这个:
.article_body p:nth-of-type(1){
background-color:green;
}
或者只是创建一个类
HTLM:<p class="yourclass"></p>
CSS:.yourclass{background-color:green;}
答案 1 :(得分:0)
我试试
.article__body p:nth-of-type(1){
background-color:green;
}