16

寻找线索,如何使用背景颜色的不透明度与过渡?

我正在使用rgba()功能,但过渡不适用于悬停。

.bx{
  background:rgba(255,0,0,0.5);
  width:100px; height:100px;
  position:relative;
  transition: opacity .5s ease-out;
  -moz-transition: opacity .5s ease-out;
  -webkit-transition: opacity .5s ease-out;
  -o-transition: opacity .5s ease-out;
}

.bx:hover{
  background:rgba(255,0,0,1);
}

.t{
  position:absolute; 
  bottom:0px;
}

HTML

<div class="bx"><div class="t">text</div></div>

任何想法,我如何使用过渡.bx

4

1 回答 1

28

事实上,opacityrgba()是完全不同的。

由于您使用属性rgba()作为背景颜色,因此background您需要使用backgroundas 转换属性,如下所示:

.bx {
  background: rgba(255,0,0,0.5);
  width:100px; height:100px;
  position: relative;

  -webkit-transition: background .5s ease-out;
  -moz-transition: background .5s ease-out;
  -o-transition: background .5s ease-out;
  transition: background .5s ease-out;
}

.bx:hover {
  background: rgba(255,0,0,1);
}

JSBin 演示

于 2013-08-21T09:11:28.263 回答