Is it possible to change only the alpha of a rgba background colour on hover?

后端 未结 14 2207
离开以前
离开以前 2020-11-29 07:04
14条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 07:43

    there is an alternative,you can add a linear-gradient background image onto the original color.

    a{
      background: green
    }
    a:hover{
      background-image:linear-gradient(hsla(0,0%,0%,.2) 100%,transparent 100%) // darker
    }
    a:hover{
      background-image:linear-gradient(hsla(255,100%,100%,.2) 100%,transparent 100%) // lighter
    }
    

    also, with css3 filter property,you can do that too,but it seems that it will change the text color

    a:hover{
       filter: brightness(80%) //darker
    }
    a:hover{
       filter: brightness(120%) //lighter
    }
    

    here is a jsfiddle:https://jsfiddle.net/zhangyu911013/epwyL296/2/

提交回复
热议问题