如何设置嵌套块 html 的第一段样式?

问题描述 投票:0回答:1
html css css-selectors
1个回答
0
投票

:nth-of-type
伪类应该做到这一点:

section:nth-of-type(2) > p:nth-of-type(1) {
  background: red;
}
<section>
  <img src="" alt="" />
</section>

<section>
  <p>//something 1</p>
  <img src="" alt="" />
  <p>//something 2</p>
  <p>//something 3</p>
</section>

<section>
  <img src="" alt="" />
</section>

<section>
  <p>//something 4</p>
  <p>//something 5</p>
</section>

© www.soinside.com 2019 - 2024. All rights reserved.