【问题标题】:background image and color change on hover with duration悬停时背景图像和颜色随持续时间变化
【发布时间】:2015-05-30 11:43:21
【问题描述】:

欢迎。 我正在尝试在悬停时在背景图像上添加颜色并持续一段时间。我已经添加了颜色蒙版,但是动画时间有问题。谁能告诉我为什么 transition-duration 在这里不起作用?

小提琴:https://jsfiddle.net/kamilm14/pysmzryn/

这是我的 HTLM 代码:

   <table style="width: 510px; border: 0px;">
     <tr>
        <td class="scandic">
        </td>
        <td style="width: 10px; height: 119px;">
        </td>
        <td class="stayinn">
        </td>
     </tr>
   </table>

还有 CSS:

.scandic {
width: 250px; height: 119px;
    background: url('http://oi61.tinypic.com/2dvlibt.jpg') no-repeat;
    background-size: 250px 119px;
    border: 0;
}

.scandic:hover {
background: linear-gradient(0deg, rgba(0,188,212,0.8), rgba(0,188,212,0.8)), url(http://oi61.tinypic.com/2dvlibt.jpg) no-repeat;
background-size:250px 119px;

}

.stayinn {
width: 250px; height: 119px;
    background-image: url('http://oi58.tinypic.com/35iztsh.jpg');
    background-repeat:no-repeat;background-size:250px 119px;
    border: 0;
}

.stayinn:hover {
background: linear-gradient(0deg, rgba(0,188,212,0.8), rgba(0,188,212,0.8)), url(http://oi58.tinypic.com/35iztsh.jpg) no-repeat;
background-size:250px 119px;
}

.scandic, .stayinn {
     -webkit-transition-duration: 2s;
    -moz-transition-duration: 2s;
    -o-transition-duration: 2s;
    transition-duration: 2s;
}

【问题讨论】:

    标签: html css background transition duration


    【解决方案1】:

    似乎是由您使用多个背景引起的。您是否考虑过使用伪元素?它们会提供更清晰的标记,让您可以很快地找到它。

    注意

    除非您正在寻找support really old browsers,否则不再需要添加前缀转换

    这是一个快速演示:

    div {
      position: relative;
      /*required*/
      height: 300px;
      width: 300px;
      background:url(http://placekitten.com/g/300/300);
    }
    div:before {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      height: 100%;
      width: 100%;
      background: rgba(0, 200, 200, 0.6);
      opacity: 0;
      transition: all 0.8s;
      /*I've reduced this to a single line (prefixing isn't needed)!*/
    }
    div:hover:before {
      opacity: 1;
    }
    &lt;div&gt;&lt;/div&gt;

    【讨论】:

    猜你喜欢
    • 2013-10-23
    • 2018-08-28
    • 1970-01-01
    • 2016-10-25
    • 1970-01-01
    • 1970-01-01
    • 2012-03-05
    • 2013-10-17
    • 2017-06-28
    相关资源
    最近更新 更多