想让鼠标离开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;
}
Take
.p2
as a child element of thea
tag, and then useposition: absolute
to adjust the positionPut 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.
If this is the case, why not put p in the A tag