[英]:first-child pseudo is not applying
I want to apply some styles to first-child of <dl>
. 我想对<dl>
第一个孩子应用某些样式。 I meant to say that should be applied to first <dd>
. 我的意思是说应该将其应用于first <dd>
。 But it works if i remove <dt></dt>
in the <dl>
. 但是,如果我删除了<dl>
中的<dl>
<dt></dt>
,它将起作用。
<dl>
<dt>Test</dt>
<dd>One</dd>
<dd>Two</dd>
<dd>Three</dd>
<dd>Four</dd>
<dd>Five</dd>
</dl>
CSS: CSS:
dl dd:first-child{border:1px solid red}
Use first-of-type
instead: 改用first-of-type
:
dl dd:first-of-type{border:1px solid red}
The :first-of-type CSS pseudo-class represents the first sibling of its type in the list of children of its parent element. :first-of-type CSS伪类表示其父元素的子代列表中其类型的第一个同级 。
-vs- 航班吗
The :first-child CSS pseudo-class represents any element that is the first child element of its parent. :first-child CSS伪类表示任何作为其父级的第一个子元素的元素 。
In your case, first-child
wont work, because the first dd
is not the first child of dl
在您的情况下, first-child
不会工作,因为第一个dd
不是dl
的第一个孩子
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.