<分区>
标签 html css css-selectors
我预计 :first 选择器的用法将由下面的示例演示。唉!段落不会随着背景变红。有人可以帮忙吗?
p:first{background:red;}
<p>This is paragraph 1.</p>
<p>This is paragraph 2.</p>
<p>This is paragraph 3.</p>
References: https://developer.mozilla.org/en/docs/Web/CSS/:first
NOTE: The question is for this particular selector demonstration. So, kindly stick to it!
最佳答案
从您链接到的引用:
The :first @page CSS pseudo-class describes the styling of the first page when printing a document.
第一段是一段,不是一页。您是在屏幕上呈现文档,而不是将其打印到纸上。
考虑 :first-child
相反。
关于html - :first selector not working in CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42437135/