代码之家  ›  专栏  ›  技术社区  ›  Devmix

鼠标滑过时如何将盒子向上移动?

  •  0
  • Devmix  · 技术社区  · 6 年前

    我只是在做鼠标悬停的时候,试着把盒子往上移动。我可以用鼠标在每个盒子上移动,但不能让它向上移动。 这是我的密码:

    body {
      text-align: center;
    }
    .row {
     padding: 50px 0;
    }
    .post-item {
     outline: 1px solid red;
     padding: 50px 20px;
     border: 5px solid transparent;
    }
    .post-item:hover {
     outline: 0px solid transparent;
      padding: 50px 20px;
      border: 5px solid red;
     }
    

    这是我的 LIVE DEMO

    3 回复  |  直到 6 年前
        1
  •  0
  •   Omid Nikrah    6 年前

    你应该使用 transform

    body {
      text-align: center;
    }
    
    .row {
      padding: 50px 0;
    }
    
    .post-item {
      outline: 1px solid red;
      padding: 50px 20px;
      border: 5px solid transparent;
      transition: all 200ms ease;
    }
    
    .post-item:hover {
      outline: 0px solid transparent;
      padding: 50px 20px;
      border: 5px solid red;
      transform: translateY(-3px);
    }
    
        2
  •  1
  •   Hanif    6 年前

    您给出的示例使用了两个CSS属性:

    .post-item:hover {
      outline: 0px solid transparent;
      padding: 50px 20px;
      border: 5px solid red;
      transform: translate3d(0,-3px,0); /* This line defining how many pixel should move */
      transition: all .15s cubic-bezier(.33,.66,.66,1); /* This line defining transition time such as here: .15s */
    }
    
        3
  •  0
  •   G Pandurengan    6 年前

      .post-item:hover{transform:translateY(-3%);}