【问题标题】:Box-shadow is being cut off of the imageBox-shadow 正在从图像中截断
【发布时间】:2021-07-18 02:39:16
【问题描述】:

图像应该是这样的。

box-shadow 添加到代码中: Image

相反,它看起来像这样,我不知道为什么以及如何解决它。 Image

您可以看到盒子阴影在图像的所有 4 个面上都被切断了。

如何修复它以使图像不会被截断?

代码:https://jsfiddle.net/8mgvn40u/

.curtain {
  width: 550px;
  height: 250px;
  border-radius: 20px;
  position: relative;
  overflow: hidden;
  background: #000000;
  box-sizing: border-box;
}

.jacketa {
  position: absolute;
  width: 180px;
  height: 180px;
  cursor: pointer;
  border-radius: 50%;
  background: #130e85;
  border: 3px solid #f91f6e;
  box-sizing: border-box;
  box-shadow: 0 0 20px 2px #f9066bf7;
   
}
.jacketa .coversvg {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  margin: auto;
  cursor: pointer;
}
.jacketa .coversvg {
  width: 70px;
  height: 75.4px;
  fill: none;
  stroke-width: 4px;
  stroke-miterlimit: 10;
}

.jacketa .coversvg .back {
  stroke: #000;
  opacity: 0.15;
}

.jacketa .coversvg .front {
  stroke: #08f9ff;
  stroke-dasharray: 150;
  stroke-dashoffset: 1500;
  animation: draw 20s infinite linear, flicker-1 2s linear 2s infinite both;
}

@keyframes draw {
  100% {
    stroke-dashoffset: 0;
  }

  100% {
    stroke-dashoffset: 0;
  }
}

@keyframes flicker-1 {
  0%,
  100% {
    opacity: 1;
  }

  41.99% {
    opacity: 1;
  }

  42% {
    opacity: 0;
  }

  43% {
    opacity: 0;
  }

  43.01% {
    opacity: 1;
  }

  47.99% {
    opacity: 1;
  }

  48% {
    opacity: 0;
  }

  49% {
    opacity: 0;
  }

  49.01% {
    opacity: 1;
  }
}

.split-wrap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 180px;
  height: 180px;
  margin: auto;
  border-radius: 50%;
  transition: 0.5s ease;
}

.j1 {
  position: absolute;
  left: 0;
  top: 0;
  width: 50%;
  height: 100%;
  overflow: hidden;
  transition: 5s ease;
}
.j2 {
  position: absolute;
  left: 50%;
  top: 0;
  width: 50%;
  height: 100%;
  overflow: hidden;
  transition: 5s ease;
}
.j2 .jacketa {
  right: 0;
  left: auto;
}
.curtain:hover .j1 {
  transform: translateX(-500%);
}
.curtain:hover .j2 {
  transform: translateX(500%);
}
<div class="curtain">

  <div class="split-wrap">
    <div class="j1">
      <div class="jacketa" title="[ Enjoy The Music ]">
        <svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
          <title>[ Enjoy The Music ]</title>
          <path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
          <path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
        </svg>
      </div>
    </div>
    <div class="j2">
      <div class="jacketa" title="[ Enjoy The Music ]">
        <svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
          <title>[ Enjoy The Music ]</title>
          <path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
          <path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
        </svg>
      </div>
    </div>
  </div>
</div>

【问题讨论】:

    标签: html css css-transitions


    【解决方案1】:

    由于溢出,bow-shadow 被截断(已经说过),您还可以使用变换轻松将阴影保持在可见区域内。

    首先增加隐藏的溢出区域,然后减少里面的内容。再小就不会被剪裁了。

    带有简短固定的想法示例:transform:scale(1.1)VS transform:scale(0.9) 以保持与初始布局大小的接近比例。

    .curtain {
      width: 550px;
      height: 250px;
      border-radius: 20px;
      position: relative;
      overflow: hidden;
      background: #000000;
      box-sizing: border-box;
    }
    .split-wrap{
    transform:scale(1.1);
    }
    .jacketa {
      position: absolute;
      width: 180px;
      height: 180px;
      cursor: pointer;
      border-radius: 50%;
      background: #130e85;
      border: 3px solid #f91f6e;
      box-sizing: border-box;
      box-shadow: 0 0 20px 2px #f9066bf7;
      transform:scale(0.9);
       
    }
    .jacketa .coversvg {
      position: absolute;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      margin: auto;
      cursor: pointer;
    }
    .jacketa .coversvg {
      width: 70px;
      height: 75.4px;
      fill: none;
      stroke-width: 4px;
      stroke-miterlimit: 10;
    }
    
    .jacketa .coversvg .back {
      stroke: #000;
      opacity: 0.15;
    }
    
    .jacketa .coversvg .front {
      stroke: #08f9ff;
      stroke-dasharray: 150;
      stroke-dashoffset: 1500;
      animation: draw 20s infinite linear, flicker-1 2s linear 2s infinite both;
    }
    
    @keyframes draw {
      100% {
        stroke-dashoffset: 0;
      }
    
      100% {
        stroke-dashoffset: 0;
      }
    }
    
    @keyframes flicker-1 {
      0%,
      100% {
        opacity: 1;
      }
    
      41.99% {
        opacity: 1;
      }
    
      42% {
        opacity: 0;
      }
    
      43% {
        opacity: 0;
      }
    
      43.01% {
        opacity: 1;
      }
    
      47.99% {
        opacity: 1;
      }
    
      48% {
        opacity: 0;
      }
    
      49% {
        opacity: 0;
      }
    
      49.01% {
        opacity: 1;
      }
    }
    
    .split-wrap {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      width: 180px;
      height: 180px;
      margin: auto;
      border-radius: 50%;
      transition: 0.5s ease;
    }
    
    .j1 {
      position: absolute;
      left: 0;
      top: 0;
      width: 50%;
      height: 100%;
      overflow: hidden;
      transition: 5s ease;
    }
    .j2 {
      position: absolute;
      left: 50%;
      top: 0;
      width: 50%;
      height: 100%;
      overflow: hidden;
      transition: 5s ease;
    }
    .j2 .jacketa {
      right: 0;
      left: auto;
    }
    .curtain:hover .j1 {
      transform: translateX(-500%);
    }
    .curtain:hover .j2 {
      transform: translateX(500%);
    }
    <div class="curtain">
    
      <div class="split-wrap">
        <div class="j1">
          <div class="jacketa" title="[ Enjoy The Music ]">
            <svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
              <title>[ Enjoy The Music ]</title>
              <path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
              <path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
            </svg>
          </div>
        </div>
        <div class="j2">
          <div class="jacketa" title="[ Enjoy The Music ]">
            <svg class="coversvg" width="70" height="75.4" viewBox="0 0 47.96 51.66">
              <title>[ Enjoy The Music ]</title>
              <path class="back" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
              <path class="front" d="M2,25.83V4.11A2.11,2.11,0,0,1,5.13,2.27L44.88,24.45a2.11,2.11,0,0,1,0,3.7L5.1,49.41A2.11,2.11,0,0,1,2,47.55V25.83" />
            </svg>
          </div>
        </div>
      </div>
    </div>

    【讨论】:

    • 我怎样才能把尺寸变成180,原来是这样的?有可能吗?
    • @coding4532 ,算一下 :) 缩小 0.9 大约是放大 1.1111 需要回到 1
    • 你是怎么算的?是什么给了你 1.1111?所以我知道该怎么做。我在计算什么?
    • @coding4532 缩小 10%:180 x 0.9 = 162 (10% = 18)。反过来是:180 / 162= 1.111.. 和 1.1111... x 162 = 180
    • 是的,同样的方法:180 x 0.8 = ... 然后使用你得到的这些数字
    【解决方案2】:

    发生这种情况是因为您将 overflow: hidden 分配给了 .j1.j2,将其更改为 overflow: visible 将解决 box-shadow 问题,但会弄乱您的窗帘动画。

    或者,您可以使.j1.j2 更大,但要使用填充,这样box-shadow 就不会重叠。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-20
      • 2012-03-14
      • 2019-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-12
      • 1970-01-01
      相关资源
      最近更新 更多