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

盒阴影动画

  •  0
  • SaroGFX  · 技术社区  · 7 年前

    我想知道为什么盒子的阴影没有反过来工作。有没有可能使它从按钮中心扩散到另一个方向?

    谢谢

    .slide {
      -webkit-transition: ease-out 0.3s;
      -moz-transition: ease-out 0.3s;
      transition: ease-out 0.3s;
      box-shadow: inset 0 0 0 0 #000;
      padding: 20px 40px 20px 40px;
    }
    
    .slide_inside:hover {
      box-shadow: inset 0 0 0 50px #000;
      background: initial;
    }
    
    .slide_outside:hover {
      box-shadow: inset 0 0 0 -50px #000;
      background: initial;
    }
    <h6>Inside</h6>
    <a href="#">
      <button class="slide slide_inside">Button</button>
    </a>
    <h6>Outside</h6>
    <a href="#o">
      <button class="slide slide_outside">Button</button>
    </a>
    2 回复  |  直到 7 年前
        1
  •  3
  •   Rainbow    7 年前

    对于阴影,你需要删除插图,这意味着开始,这就是为什么没有 outset 关键字,并且正如您所知,无法将属性从零转换为必须具有初始值的属性,这就是为什么我们从无开始/插入。

    body {
      display: flex;
      align-items: center;
      flex-direction: column;
    }
    
    .slide {
      -webkit-transition: ease-out 0.3s;
      -moz-transition: ease-out 0.3s;
      transition: ease-out 0.3s;
      box-shadow: none 0 0 0 0 #000;
      padding: 20px 40px 20px 40px;
    }
    
    .slide_inside:hover {
      box-shadow: inset 0 0 0 50px #000;
      background: initial;
    }
    
    .slide_outside:hover {
      box-shadow: 0 0 0 50px #000;
      background: initial;
    }
    <h6>Inside</h6>
    <a href="#">
      <button class="slide slide_inside">Button</button>
    </a>
    <h6>Outside</h6>
    <a href="#o">
      <button class="slide slide_outside">Button</button>
    </a>
        2
  •  0
  •   Temani Afif    7 年前

    您可以合并多个 box-shadow

    .slide {
      transition: linear 0.3s;
      box-shadow: 
        inset 0 0 0 30px #000,
         0 0 0 0px #000;
      padding: 20px 40px 20px 40px;
      margin:50px;
      color:#fff;
    }
    
    
    .slide_outside:hover {
      box-shadow: 
        inset 0 0 0 0px #000,
        0 0 0 30px #000;
      color:#000;
    }
    <h6>Outside</h6>
    <a href="#o">
      <button class="slide slide_outside">Button</button>
    </a>