Mon*_*ffy 6 html css css3 css-transitions
当我在另一个div上盘旋时,我试图动画div.我有以下代码
HTML
<div>
</div>
<div class="content">
</div>
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是,我需要动画.content到margin-top:-100px和margin-left:50px; 当用户将鼠标悬停在其中一个元素上时,从其默认位置开始.但是使用此代码的atm仅在用户将鼠标悬停在.content上并且以其他方式设置动画时才有效.(从margin-top:-100px和margin-left:50px;到默认位置).请原谅我的英语
jsfiddle-> http://jsfiddle.net/fTAUk/1/
您需要将内容包装在div中并使用子选择器.注意我也给了较大的div一个id.这是css:
#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;
}
Run Code Online (Sandbox Code Playgroud)