Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在元素悬停时更改另一个元素属性。到目前为止,我想出了以下 CSS:
#test3:hover #test4 { background-color: red; } <div id="test3">three</div> <div id="test4">four</div>
但是,这是行不通的。这可能吗?你有什么建议?
#test3:hover #test4
这意味着,定位一个元素test4,它是 的子元素test3。您想要+ 兄弟选择器:
test4
test3
+
#test3:hover + #test4 { background-color: red; }
浏览器兼容性表