[英]Can i handle other elements when hover?
HTML,
<div id="first">
<a>Come here</a>
</div>
<div id=second">
second div
</div>
CSS,
#first a:hover{
color:green;
/*i want to do this when hover */
#second{
background:green;
}
}
在這里,如果用戶光標轉到“來這里”,我想改變其他元素#second的背景顏色。
這只能使用css嗎? 或者我必須使用jquery或javascript事件?
#first:hover + #second{
background: green;
}
http://jsfiddle.net/DerekL/8rJmC/
如果#second
不在#first
之后,請使用~
。
請注意,這是不可能的附加:hover
事件a
直接只使用CSS。 上面的代碼將它附加到#first
。
你可以用jQuery做這樣,如果你真的把它連接到a
:
$("#first > a").hover(function(){
$("#second").css(...);
}, ....);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.