Css 第一个子选择器不适用于dd
dd上的第一个子选择器不工作,为什么Css 第一个子选择器不适用于dd,css,css-selectors,Css,Css Selectors,dd上的第一个子选择器不工作,为什么 <dl> <dt>definition term</dt> <dd>description</dd> <dd>description</dd> <dd>description</dd> </dl> dd:first-child{ /*styling here not work*/ } 定义术语
<dl>
<dt>definition term</dt>
<dd>description</dd>
<dd>description</dd>
<dd>description</dd>
</dl>
dd:first-child{
/*styling here not work*/
}
定义术语
描述
描述
描述
dd:第一个孩子{
/*这里的样式不起作用*/
}
您应该改用伪类
dd:类型的第一个{
背景颜色:金色;
}
这是因为
不是其父级的第一个子级
表示其父级的第一个子级,与元素
匹配。在这个特定实例中,
元素的第一个子元素是
元素;不是
从:
CSS伪类的:first of type
表示
它在其父元素的子元素列表中的类型
类型的术语指的是HTML元素类型。因此,dd:first of type
在其父元素的子元素树中选择第一个
元素
或者,在这种特殊情况下,您可以使用as:dt+dd
选择第一个
元素应该是
dd:first-of-type{
display: none;
}
实现跨浏览器兼容性(
dt + dd {
display:none;
}