首页 > 解决方案 > 如何摆脱悬停效果动画显示的这条线?

问题描述

更新:我终于想通了。我不得不在 .services-cell:hover 类中添加溢出:隐藏。

因此,当我将鼠标悬停在图像上时,会出现这种白色条带效果,但是当我将鼠标悬停在图像上时,它会显示一条穿过方形边框的小线,即使形状是多边形。所以基本上想象一个白条从多边形的右上角到左下角。

这是一个代码笔https://codepen.io/designextras/pen/QWybXvR 显示那条小线。即使没有图像显示,当您将鼠标悬停在形状上时它仍然会显示。

我不确定如何摆脱条形图到达图像左下角时显示的那条小线。请注意,当我将鼠标悬停在左上角时,它也会显示线条,所以它看起来有点像边界线效果,但不确定发生了什么。

在此处输入图像描述

这是创建效果的 HTML 和 CSS:

html, body {
  background: #222;
  display: flex;
  height: 100%;
  overflow: hidden;
  align-items: center;
  justify-content: center;
}

.services-cell:before {
  content: '';
  position: absolute;
  opacity: 0.4;
  width: 350px;
  height: 70px;
  background: white;
  top: 50;
  left: 0;
  z-index: 1;
  transform: rotate(45deg);
  transition: transform 0.5s;
}

.services-cell:hover:before {
  transform: translate(-100px, 600%) rotate(45deg);
  transition: transform 0.5s;
}

.services-cell {
  flex: 0 1 250px;
  max-width: 250px;
  height: 275px;
  margin: 2px 2px;
  position: relative;
  text-align: center;
  z-index: 1;
  box-shadow: 0px 0px 15px 0 rgba(0, 0, 0, 0.8);
  -webkit-clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
  cursor: pointer;
}

.services-cell_img {
  object-fit: cover;
  object-position: center;
}

.services-cell_text {
  height: 100%;
  width: 60%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-transform: uppercase;
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  transition: opacity 350ms;
}
 
//This is the code that causes the lines
.services-cell:hover {
opacity: 1;
transition: all 0.3s ease-in-out;
transform: scale(1.2);
-webkit-transform: scale(1.2);
z-index: 99;
}
<div class="services-cell">
  <img class="services-cell_img" src="https://placehold.it/250x275" alt="">
  <div class="services-cell_text">Digital Marketing</div>
</div>

标签: htmlcss

解决方案


.services-cell:hover, .services-cell_text { 不缩放超过1,所以改变:

transform: scale(1.2);
to
transform: scale(1);

或者如果您想保持调整大小,请添加:

 overflow: hidden;

推荐阅读