gpt4 book ai didi

html - :first-child pseudo is not applying

转载 作者:太空宇宙 更新时间:2023-11-03 20:43:24 24 4
gpt4 key购买 nike

我想对 <dl> 的第一个 child 应用一些样式.我的意思是说应该先应用于 <dd> .但如果我删除 <dt></dt> 它会起作用在<dl> .

<dl>
<dt>Test</dt>
<dd>One</dd>
<dd>Two</dd>
<dd>Three</dd>
<dd>Four</dd>
<dd>Five</dd>
</dl>

CSS:

dl dd:first-child{border:1px solid red}

最佳答案

使用 first-of-type相反:

dl dd:first-of-type{border:1px solid red}

Demo Fiddle


推理...

first-of-type

The :first-of-type CSS pseudo-class represents the first sibling of its type in the list of children of its parent element.

-对比-

first-child

The :first-child CSS pseudo-class represents any element that is the first child element of its parent.

在你的例子中,first-child不会工作,因为第一个 dd不是 dl第一个 child

关于html - :first-child pseudo is not applying,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23804354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com