【问题标题】:Animating an element when hovering on two other element using css使用css将鼠标悬停在其他两个元素上时为元素设置动画
【发布时间】:2013-06-16 12:18:47
【问题描述】:

我试图在悬停在另一个 div 上时为 div 设置动画。我有以下代码

html

<div>
</div>
<div class="content">
</div>

css

div {
    height: 100px;
    width: 100px;
    background: red; 
        transition: all 0.4s ease-in-out;
}
.content {
    height: 20px;
    width: 20px;
    background: green;
    display: none;

}
div:hover + .content{
    display: block;
    margin-top: -100px;
    margin-left: 50px;
}

我想要做的是,我需要将 .content 设置为 margin-top: -100px 和 margin-left: 50px;当用户将鼠标悬停在这些元素之一上时,从其默认位置开始。但是使用此代码的 atm 仅当用户将鼠标悬停在 .content 上并且它以另一种方式设置动画时才有效。 (从 margin-top: -100px 和 margin-left: 50px; 到默认位置)。请原谅我的英语

jsfiddle-> http://jsfiddle.net/fTAUk/1/

【问题讨论】:

  • 你的动画似乎不是好的 DIV

标签: html css css-transitions


【解决方案1】:

您需要将内容包装在 div 中并使用子选择器。注意我也给了较大的 div 一个 id。这是css:

JS Fiddle

#box {
    height: 100px;
    width: 100px;
    background: red;
    position: absolute;
    transition: all 0.4s ease-in-out;
}
#content {
    width: 20px;
    background: green;
    height: 0;
    transition: all 0.4s ease-in-out;
    position: margin-top: -100px;
    margin-left: 50px;
    -webkit-transition: all .8s ease;
    -moz-transition: all .8s ease;
    -ms-transition: all .8s ease;
    -o-transition: all .8s ease;
    transition: all .8s ease;
}
#box:hover > #content {
    height: 20px;
}

【讨论】:

  • 没问题,顺便用工作过渡编辑它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-05
  • 1970-01-01
  • 2021-04-28
  • 2012-10-01
  • 2016-08-03
  • 1970-01-01
相关资源
最近更新 更多