想让鼠标离开a元素移到p2上p2依旧显示,但是移到a元素和p2以外的地方就还是不显示
<a href="#">hover</a>
<p class="p2">
</p>
a:hover + .p2{
display: block;
animation: 0.5s p2 ease-in forwards;
}
@keyframes p2{
0%{height: 0; }
100%{height: 200px; }
}
.p2{
width: 200px;
background-color: red;
}
黄舟2017-04-17 11:46:34
Take .p2
as a child element of the a
tag, and then use position: absolute
to adjust the position
伊谢尔伦2017-04-17 11:46:34
<a href="#">hover
<p class="p2">
</p>
</a>
<style>
a:hover .p2{
display: block;
animation: 0.5s p2 ease-in forwards;
}
@keyframes p2{
0%{height: 10px; }
100%{height: 200px; }
}
.p2{
width: 200px;
background-color: red;
}
</style>
这样修改可以达到你要的效果
怪我咯2017-04-17 11:46:34
Put the a tag and p in the same p, and js sets the hover method of the parent p. You can also put p in the a tag, set the a tag to display: block; and then adjust it with positioning, floating, etc. Location.