简单的CSS过渡 - 没有任何工作

时间:2018-05-07 23:04:00

标签: html css hover css-transitions

我正在处理一个悬浮时消失的渐变图像。但是,我无法转换。我已经尝试了我所知道的每个webkit过渡,但它似乎并不想工作。

这是HTML:

<a href="http://calvarygigharbor.com/heavenly-hitters/">
<div class="tinted-image"> </div></a>

使用这个CSS:

.tinted-image {
 -webkit-transition: all .7s ease;
transition: all .7s ease;
position: relative;
width: 100%;
padding-top: 56.25%; /* 16:9 Aspect Ratio */
border-radius: 10px;

background:  
linear-gradient(
  rgba(255, 0, 0, 0.6), 
  rgba(237,240,0,0.6)
),
/* image */
url(http://calvarygigharbor.com/wp-content/uploads/2018/05/church-softball-2018.jpg);
background-size: contain;
}

.tinted-image:hover {
 -webkit-transition: all .7s ease;
transition: all .7s ease;
position: relative;
width: 100%;
padding-top: 56.25%; /* 16:9 Aspect Ratio */
border-radius: 10px;
background: 

/* image */
url(http://calvarygigharbor.com/wp-content/uploads/2018/05/church-softball-2018.jpg);
background-size: contain;
}

图片和悬停工作精美地减去过渡。你将如何过渡到这个?

网址:http://calvarygigharbor.com/css-testing/

1 个答案:

答案 0 :(得分:2)

您无法在渐变上应用转场,您可以尝试在background-size上添加转场。使用background-size的不同值来调整转换的工作方式,您还可以更改background-position

.tinted-image {
  -webkit-transition: all .7s ease;
  transition: all .7s ease;
  position: relative;
  width: 100%;
  padding-top: 56.25%;
  /* 16:9 Aspect Ratio */
  border-radius: 10px;
  background: linear-gradient( rgba(255, 0, 0, 0.6), rgba(237, 240, 0, 0.6)),
  /* image */
  url(http://calvarygigharbor.com/wp-content/uploads/2018/05/church-softball-2018.jpg);
  background-size:100% 100%, contain;
  background-position:center,center; /*OR [left,center] OR [top,center] ...*/ 
  background-repeat:no-repeat;
}

.tinted-image:hover {
  -webkit-transition: all .7s ease;
  transition: all .7s ease;
  position: relative;
  width: 100%;
  padding-top: 56.25%;
  /* 16:9 Aspect Ratio */
  border-radius: 10px;
  background-size:0 0,contain; /* OR [100% 0,contain] OR [0 100%,contain] */
}
<a href="http://calvarygigharbor.com/heavenly-hitters/">
  <div class="tinted-image"> </div>
</a>

相关问题