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

后端 未结 14 2203
离开以前
离开以前 2020-11-29 07:04
14条回答
  •  时光取名叫无心
    2020-11-29 07:36

    I had a similar problem. I had 18 different divs working as buttons, and each with a different color. Rather than figure out the color codes for each or use a div:hover selector to change the opacity (which affects all children) I used the pseudo-class :before like in @Chris Boon's answer.

    Because I wanted to do the coloring on the individual elements, I used :before to create a transparent white div on :hover. This is a very basic washout.

    #categories div {
        position:relative;
        width:100px;
        height:100px;
        float:left;
        border:1px solid black;
        display:table-cell;
    }
    
    #categories div:before{
        content:"";
        position:absolute;
        top:0px;
        left:0px;
        width:100px;
        height:100px;
    }
    
    #categories div:hover:before {
        background-color:white;
        opacity:0.2;
    }
    
    #a_Particular_Div {
        background-color:red;
    }
    

    According to CanIUse.com, this should have something like 92% support as of early 2014. (http://caniuse.com/#feat=css-gencontent)

提交回复
热议问题