盒子阴影悬停过渡闪烁

问题描述 投票:0回答:3

我试图通过使黑色背景从左到右来实现,使盒子阴影像幻灯片上的幻灯片一样工作。但如果没有这个奇怪的眨眼问题,我无法做到。我已经在Stack Overflow上寻找解决方案了。

我也尝试了一个部分而不是img,但结果是一样的。

Here's the JSFiddle demo

HTML

<section>
</section>

CSS

section {
  border:black 1px solid;
  width:500px;
  height:200px;
  transition:1s ease-out
}

section:hover{
  box-shadow:inset 500px 0 0 #222;
  float:left;
  transition:1s ease-out;
}
css hover transition slide box-shadow
3个回答
0
投票

这似乎是box-shadow绘制方式的结果。尝试另一种方法。这是一个无闪烁的解决方案,加厚左边框而不是添加框阴影:

div {
  position: relative;
  display: inline-block;
}
section {
  border: black 1px solid;
  width: 500px;
  height: 200px;
  transition: 1s ease-out;
  box-sizing: border-box;
}

div:hover section {
  border-left-width: 500px;
  float: left;
  transition: 1s ease-out;
}

section~* {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
  color: #888;
}
<div class="prog">
  <section></section>
  <p>Here's some text content.</p>
</div>

https://jsfiddle.net/k5kznmvL/


2
投票

使用简单伪元素并通过更改其右属性将过渡应用于宽度的另一种解决方案:

section {
  border: black 1px solid;
  width: 500px;
  height: 200px;
  position:relative;
  color:#c2c2c2;
  text-align:center;
  padding-top:50px;
  box-sizing:border-box;
}

section:before {
  position: absolute;
  content: " ";
  top: 0;
  bottom: 0;
  left: 0;
  background: #000;
  right: 100%;
  transition:1s ease-out;
  z-index:-1;
}
section:hover::before {
  right:0;
}
<section>
  add your text here
</section>

0
投票

您还可以简单地将某种框阴影模拟添加到初始状态,该状态具有非常小的扩散半径。

  section {
      box-shadow: inset 0 0 0 0.01px white;
  }
© www.soinside.com 2019 - 2024. All rights reserved.