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

凹凸形分割

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

    我正在处理div的凹凸形状。我想要一个凹面形状,鼠标悬停,它就会变成凸面。有人能给我指出正确的方向吗?到目前为止,这是我尝试的示例代码,下面是图片

    .section {
      position: relative;
      overflow: hidden;
      padding: 50px 0;
    }
    
    .inner {
      position: relative;
      background: black;
      height: 120px;
    }
    .inner:after {
      box-shadow: 0 0 0 80px #000;
      border-radius: 100%;
      position: absolute;
      height: 150px; 
      content: '';
      right: -20%;
      left: -20%;
      top: 100%;
    	transition: all 0.4s ease-in-out;
    }
    
    .inner:after {
      bottom: 100%;
      top: auto;
    }
    
    .inner:hover:after {
    	height: 0;
    }
    <div class="section">
      <div class="inner"></div>
    </div>
    1 回复  |  直到 6 年前
        1
  •  1
  •   Observer    6 年前

    你很接近。你可以用 :before 和“:after”以实现该功能。 :之前 top 位置。

    .card {
        height: 100px;
        background-color: tomato;
    }
    .section {
      top: 50px;
      position: relative;
      overflow: hidden;
      padding: 50px 0 0;
    }
    
    .inner {
      position: relative;
      background: black;
      height: 120px;
    }
    .inner:after {
      box-shadow: 0 0 0 80px #000;
      border-radius: 100%;
      position: absolute;
      height: 150px; 
      content: '';
      right: -20%;
      left: -20%;
      top: -150px;
    	transition: all 0.4s ease-in-out;
    }
    
    .inner:hover:after {
    	top: -120px;
    }
    
    .inner:before {
        box-shadow: 0 0 0 80px #000;
      border-radius: 100%;
      position: absolute;
      height: 150px; 
      content: '';
      right: -20%;
      left: -20%;
      top: 130px;
    	transition: all 0.4s ease-in-out;
    }
    
    .inner:hover:before {
    	top: 50px;
    }
    <div class='card'>
      <div class="section">
        <div class="inner"></div>
      </div>
    </div>