search

Home  >  Q&A  >  body text

前端 - a:hover时滑出div2,想在鼠标离开a到了div2上面该div2依旧显示,移到其它地方还是保留a:hover效果。

想让鼠标离开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;
        
    }
怪我咯怪我咯2782 days ago602

reply all(4)I'll reply

  • 黄舟

    黄舟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

    reply
    0
  • 伊谢尔伦

    伊谢尔伦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>
    
    这样修改可以达到你要的效果

    reply
    0
  • 怪我咯

    怪我咯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.

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 11:46:34

    If this is the case, why not put p in the A tag

    reply
    0
  • Cancelreply