我期望使用:第一个选择器通过以下示例进行演示。唉!段落不会随背景变红。有人可以帮忙吗?
p:first{background:red;}
<p>This is paragraph 1.</p>
<p>This is paragraph 2.</p>
<p>This is paragraph 3.</p>
参考文献:https://developer.mozilla.org/en/docs/Web/CSS/:first
注意:问题在于此特定选择器演示。所以,请坚持下去!
答案 0 :(得分:3)
答案 1 :(得分:1)
jQuery有一个名为:first的选择器,但它与CSS无关:第一选择器。
$("p:first").css ("background", "red");
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>This is paragraph 1.</p>
<p>This is paragraph 2.</p>
<p>This is paragraph 3.</p>
&#13;
答案 2 :(得分:0)
您需要添加子项:
号码:第一胎{背景:红色;}
p:first-child{background:red;}
&#13;
<p>This is paragraph 1.</p>
<p>This is paragraph 2.</p>
<p>This is paragraph 3.</p>
&#13;