特定类型的第一个子元素 [英] first child element of particular type
本文介绍了特定类型的第一个子元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带三个孩子的部分(一个<h1>
和两个<div>
)
I have some section with three children (one <h1>
and two <div>
)
<section class="half">
<h1>Half</h1>
<div>
left half
</div>
<div>
right half
</div>
</section>
然后我要在这些块中添加一些样式
Then I am adding some styles to these blocks
section > h1 { ... }
section > div { ... }
我想为该部分的第一个<div>
元素指定其他样式.
I want to specify additional styles for the first <div>
element in the section.
我不能只用section > :first-child
书写,因为本节中的第一个孩子是<h1>
.
I can't write use just section > :first-child
because first child in section is <h1>
.
那我应该怎么写?
推荐答案
That's what :nth-of-type
is for:
section > div:nth-of-type(1) {
/* CSS properties go here... */
}
这篇关于特定类型的第一个子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文