将 2 个不同的 div 悬停在第三个不同的 div 上 [英] Move 2 different divs on hover on a third different div

查看:22
本文介绍了将 2 个不同的 div 悬停在第三个不同的 div 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面有 3 个水平放置的 div.当中心 div 悬停时,我需要让 2 个 div 移动到页面的两侧(左 div 向左移动,右 div 向右移动).我可以让左边的 div 移动,但右边的 div 没有移动.我希望使用 CSS 来实现这一点,如果没有请告知.非常感谢.

My page has 3 divs that are located horizontally. I need to make the 2 divs move to the sides of the page (left div move to left, and right div move to right) when the center div is on hover. I can make the left div move, but the right div isn't moving. I hope to get this achieved using CSS, if not please advise. Thanks a lot.

我的代码如下:

.container 
   {
    position:absolute; bottom:0; right:0; left:0;
    margin-right:auto; margin-left:auto;
    width:50%; height:10%;
   }
.a {position:absolute; bottom:0; left:20px; width:30%;}
.b 
   {
    position:absolute; bottom:0; right:0; left:0;
    margin-right:auto; margin-left:auto; width:30%;
   }
.c {position:absolute; bottom:0; right:20px; width:30%;}

.b:hover + .a{
-moz-transform:translatex(-50px);
-ms-transform:translatex(-50px);
-o-transform:translatex(-50px);
-webkit-transform:translatex(-50px);
transform:translatex(-50px);
}

.b:hover + .c{
-moz-transform:translatex(50px);
-ms-transform:translatex(50px);
-o-transform:translatex(50px);
-webkit-transform:translatex(50px);
transform:translatex(50px);
}

<div class="container">
    <div class="b">Div b</div>
    <div class="a">Div a</div>
    <div class="c">Div c</div>
</div>

推荐答案

将选择器从 + 改为 ~:

change the selectors from + to ~:

.b:悬停~.a{

.b:hover ~ .c{

.b:hover ~ .c{

http://jsfiddle.net/YYhTS/

这篇关于将 2 个不同的 div 悬停在第三个不同的 div 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆