English 中文(简体)
顶部 div 的 Hover 背景吗?
原标题:Hover background for topmost div?
  • 时间:2012-05-23 01:13:06
  •  标签:
  • html
  • css

看一看:

http://jsfiddle.net/PPSHd/" rel="no follow" >http://jsfiddle.net/PPSHd/

如预期的那样,在中流体上盘旋会触发所有中流体的盘旋事件。 是否有办法可以改变在悬浮鼠标下仅第1个中流体的背景? 也就是说, 中流体上盘旋只会改变中流体的颜色?

编辑: 对于用户添加的任意数量的嵌套迪夫来说, 这需要可能性, 我可以用刺绣来做, 但更喜欢 CSS 解决方案 。

我已经在使用:

(function(){
    var highlightedDiv;
    $(document.body).on( mouseover , div ,function(e){
        if(highlightedDiv){
            highlightedDiv.style.backgroundColor=  ;
        }
        (highlightedDiv=this).style.backgroundColor =  lightGray ;
        e.stopPropagation();
    });
}
)()

最佳回答

- 我看不出你怎样才能在CSS里做到

如果你乐于使用一些jQuery - 你可以做到这一点:

$("DIV").bind("hover",function(event){
    $(".Hover").removeClass("Hover");
    $(this).addClass("Hover");     
    event.stopPropagation();
 });

CSS :

div{
    padding-top:50px;
    margin:auto;
    border:1px solid lightGray;
    background:gray;
}
.Hover{
    background:lightGray;
}

关键在于阻止事件波及到其他 divs - 你 < a href=>"http://jsfidle.net/ QNBEe/" rel="no follow" > 可以在行动中看到 。

问题回答

您无法嵌套 divs。 如果您把它们放在对方身上并设置 z- index, 您可以为此使用 cs 。

http://jsfiddle.net/t9znR/





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签