gpt4 book ai didi

html - 为什么:first-child selector not working in this case?

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

参见示例 http://jsfiddle.net/qqyYU/1/

<div class="detail">

<p><b>Entry</b><br>

First <span>40,-</span><br>

Second <span>20,-</span></p></div>

CSS

.detail p span:first-child {background:yellow;}

最佳答案

您的第一个 child <p><b>标签,不是 <span> :

“此伪类匹配一个元素仅当它是其父元素的第一个子元素。” (http://reference.sitepoint.com/css/pseudoclass-firstchild)

编辑如果您不能更改元素的类并且您需要支持 IE7(尽管它可能不起作用),您可以使用相邻的兄弟选择器:

http://jsfiddle.net/qqyYU/5/

关于html - 为什么:first-child selector not working in this case?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9051523/

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