css transition opacity of the background color

后端 未结 1 1896
忘了有多久
忘了有多久 2020-12-15 09:10

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.

相关标签:
1条回答
  • 2020-12-15 09:33

    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.

    0 讨论(0)
提交回复
热议问题