CSS转换因背景图片网址而失败 [英] CSS transition fails for background-image url

查看:65
本文介绍了CSS转换因背景图片网址而失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的示例可以在链接悬停上产生淡入效果?



我这样做了: http://jsfiddle.net/felipelalli/ ns9d1vug /

 < div class = fade /> 

.fade {
-o-transition:0.3s;
-moz-transition:0.3秒;
-khtml-transition:0.3s;
-webkit-transition:0.3s;
-ms-transition:0.3s;
转换:0.3秒;

width:128px; height:128px;
background:url('http://nuclearpixel.com/content/icons/2010-02-09_stellar_icons_from_space_from_2005/earth_128.png')
}

.fade:hover {
颜色:#b50000;
width:128px; height:128px;
background:url('http://upload.wikimedia.org/wikipedia/commons/b/b2/Crystal_128_babelfish.png')
}

为什么它在Chrome浏览器中工作正常,但在Firefox上却不行?

解决方案

它在FF中不起作用,因为Firefox不支持转换背景图片,仅支持背景色。
如果要转换背景图像,请使用两个单独的< div>



  .fade div {-o-transition:0.3s; -moz-transition:0.3s; -khtml-transition:0.3s; -webkit-transition:0.3s; -ms-transition:0.3s; transition :0.3秒;宽度:128像素;高度:128像素;位置:绝对;顶:0; left:0;}。fade {position:relative;宽度:128像素;高度:128像素; } .backone {z-index:1;背景:url(’http://nuclearpixel.com/content/icons/2010-02-09_stellar_icons_from_space_from_2005/earth_128.png’); } .backtwo {background:url(’http://upload.wikimedia.org/wikipedia/commons/b/b2/Crystal_128_babelfish.png’); opacity:0; z-index:5;}。fade:hover .backtwo {opacity:1;}。fade:hover .backone {opacity:0;}  

< pre class = snippet-code-html lang-html prettyprint-override> < div class = fade>< div class = backone>< / div>< div class = backtwo>< / div>< / div>


Following examples found on Fade Effect on Link Hover?

I made this: http://jsfiddle.net/felipelalli/ns9d1vug/

<div class="fade"/>

.fade {
-o-transition: 0.3s;
-moz-transition: 0.3s;
-khtml-transition: 0.3s;
-webkit-transition: 0.3s;
-ms-transition: 0.3s;
transition: 0.3s;

 width:128px;height:128px;
background:url('http://nuclearpixel.com/content/icons/2010-02-09_stellar_icons_from_space_from_2005/earth_128.png')
}

.fade:hover {
color: #b50000;
    width:128px;height:128px;
 background:url('http://upload.wikimedia.org/wikipedia/commons/b/b2/Crystal_128_babelfish.png')
}

Why it works fine in Chrome but not Firefox?

解决方案

It isn't working in FF, because Firefox does not support transitioning a background image, only background-color. If you want to transition a background image, use two separate <div>:

.fade div {
-o-transition: 0.3s;
-moz-transition: 0.3s;
-khtml-transition: 0.3s;
-webkit-transition: 0.3s;
-ms-transition: 0.3s;
transition: 0.3s;
 width:128px;
  height:128px;
  position:absolute;
  top:0;
  left:0;
}
.fade{
  position:relative;
  width:128px;
  height:128px;
  }
.backone{
  z-index:1;
  background:url('http://nuclearpixel.com/content/icons/2010-02-09_stellar_icons_from_space_from_2005/earth_128.png');
  }
.backtwo{
background:url('http://upload.wikimedia.org/wikipedia/commons/b/b2/Crystal_128_babelfish.png');
  opacity:0;
z-index:5;
}
.fade:hover .backtwo{
opacity:1;
}
.fade:hover .backone{
opacity:0;
}

<div class="fade">
<div class="backone"></div>
<div class="backtwo"></div>
</div>

这篇关于CSS转换因背景图片网址而失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆