gpt4 book ai didi

html - CSS 正文 :first-child

转载 作者:太空狗 更新时间:2023-10-29 14:40:48 26 4
gpt4 key购买 nike

有人可以向我解释为什么这不起作用吗?

<html>
<head>
<style>
body:first-child
{
color:#f00;
}
</style>
</head>
<body>
<div>I should be red.</div>
<div>This is not red.</div>
</body>
</html>

根据我的阅读,第一个子选择器应该从 body 标记中选择第一个 div 对象。如果它没有选择 div 元素,那么它在选择什么?

最佳答案

:first-child body:first-child 中的伪类对 body 标签进行操作,因此如果您想要 body 的第一个 child 使用 child selector

body > :first-child{
color:#f00;
}

这会给你 body 的第一个 child 。

关于html - CSS 正文 :first-child,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12080101/

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