(HTML)
<div>
<h2>I am another awesome h2</h2>
<p>number one paragraph</p>
<p>I'm the second paragraph inside this div!</p>
</div>
<p>PARAGRAPH NOT INSIDE A DIV</p>
<div>
<h2>A less awesome h2</h2>
<p>number one</p>
<p>One last paragraph here!</p>
</div>
(CSS)
我尝试使用nth-of-type和nth-child,但我无法选择第二个DIV内的两个P元素。
有人可以帮忙吗?
注意:我的网页中有太多的P标签和DIV,我想选择它们,但不想使用类或ID。
div p {.../*styles for p-tags inside a div*/...}
将选择您的情况下div
内的所有p
。或者您只需要选中第二个p
? - Banzay