highlight div1 and div2 on div2 mousover, highlight nothing on div1 mouseover

余生长醉 提交于 2019-12-02 13:28:44

I changed up your CSS a little bit. Basically to make it bigger.

The order is important here.

This is not perfect due to the outer div's border.

<style>
div {
    border:1px dotted black;
    font-family:Courier;
    background:white;
}

div#top, div#bottom {
    height: 200px;
    width: 200px;
}

div#outer:hover #bottom:hover {
    background:blueviolet;
}

div#outer:hover #top {
    background:green;
}

div#outer #top:hover{
    background:white;
}

div#outer{
    display:inline-block;
    border:2px solid red;
}
</style>

Is this what you're looking for?

div#outer:hover div#top:hover, div#bottom:hover{
    background:white;
}

Alternatively, you could also use !important:

div#top:hover {
    background: white !important;
}

I don't think you can do this... CSS selection only works one way, from parent to child or in cascade.... so you can only change the CSS of divs below another div.

For example look this jsFiddle: as you can see, only the bottom divs' style can change.

This code

div#fourth:hover ~ #first{
    background:green;
}

doesn't work because the "first" div is above the "fourth" div...

Anyway, if you want to set the background of top div to white, you will see a rollover with the delay.

PS: Sorry for my bad English.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!