gpt4 book ai didi

html - css hover 不适用于先例元素

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

我想在元素悬停时更改另一个元素属性。到目前为止,我想出了以下 CSS:

#test3:hover #test4
{
background-color: red;
}

<div id="test3">three</div>
<div id="test4">four</div>

但是,这是行不通的。这可能吗?你有什么建议?

最佳答案

#test3:hover #test4

这意味着,目标元素 test4test3 的子元素。你想要 + sibling selector相反:

#test3:hover + #test4
{
background-color: red;
}

Browser compatibility table

关于html - css hover 不适用于先例元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15000342/

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