如果我悬停在第一个 Div 上,其他三个 Div 会受到影响。但是我将鼠标悬停在第二个 Div 上,只有下一个 Div 受到影响,而不是上一个。第三和第四也是一样。
这里是 HTML 代码:
<div id="hover1">
<div class="portfolio_box_skin_2" id="mask1">
<div class="portfolio_image_skin2">
Content1
</div>
<div class="cleardiv"></div>
</div></div>
<div id="hover2">
<div class="portfolio_box_skin_2" id="mask2">
<div class="portfolio_image_skin2">
Content2
</div>
<div class="cleardiv"></div>
</div></div>
<div id="hover3">
<div class="portfolio_box_skin_2" id="mask3">
<div class="portfolio_image_skin2">
Content3
</div>
<div class="cleardiv"></div>
</div></div>
<div id="hover4">
<div class="portfolio_box_skin_2" id="mask4">
<div class="portfolio_image_skin2">
Content4
</div>
<div class="cleardiv"></div>
</div></div>
和CSS代码:
#hover1,#hover2,#hover3,#hover4
{
width:100px;
height:100px;
float:left;
}
.portfolio_image_skin2
{
width:100px;
height:100px;
}
#mask1,#mask2,#mask3,#mask4
{
opacity:1;
background-color:#0CF;
}
#hover1:hover + #hover2 #mask2,
#hover1:hover ~ #hover3 #mask3,
#hover1:hover ~ #hover4 #mask4
{
/* CSS */
display:block!important;
opacity:0.5;
transition: 0.5s all;
padding-right:19px;
}
#hover2:hover + #hover3 #mask3,
#hover2:hover ~ #hover4 #mask4,
#hover2:hover ~ #hover1 #mask1
{
/* CSS */
display:block!important;
opacity:0.5;
transition: 0.5s all;
padding-right:19px;
}
#hover3:hover ~ #hover1 #mask1,
#hover3:hover ~ #hover2 #mask2,
#hover3:hover ~ #hover4 #mask4
{
/* CSS */
display:block!important;
opacity:0.5;
transition: 0.5s all;
padding-right:19px;
}
#hover4:hover + #hover1 #mask1,
#hover4:hover ~ #hover2 #mask2,
#hover4:hover ~ #hover3 #mask3
{
/* CSS */
display:block!important;
opacity:0.5;
transition: 0.5s all;
padding-right:19px;
}
用于演示目的的 Css 代码太高了。
我在 Fiddle 中做了一个演示,点击这里查看演示。