Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

looking for clue, how to use the opacity in background color with transition?

I'm using rgba() function, but the transition is not working on hover.

.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>

Any idea, how can I use transition for .bx?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
507 views
Welcome To Ask or Share your Answers For Others

1 Answer

In fact, opacity and rgba() are completely different.

Since you are using the rgba() as the background color by the background property, you'll need to use background as transition property as follows:

.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 Demo.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...