Set opacity of background image without affecting child elements

前端 未结 15 2184
闹比i
闹比i 2020-11-22 01:39

Is it possible to set the opacity of a background image without affecting the opacity of child elements?

Example

All links in the footer need a custom bull

15条回答
  •  孤街浪徒
    2020-11-22 02:34

    To really fine-tune things, I recommend placing the appropriate selections in browser-targeting wrappers. This was the only thing that worked for me when I could not get IE7 and IE8 to "play nicely with others" (as I am currently working for a software company who continues to support them).

    /* color or background image for all browsers, of course */            
    #myBackground {
        background-color:#666; 
    }
    /* target chrome & safari without disrupting IE7-8 */
    @media screen and (-webkit-min-device-pixel-ratio:0) {
        #myBackground {
            -khtml-opacity:.50; 
            opacity:.50;
        }
    }
    /* target firefox without disrupting IE */
    @-moz-document url-prefix() {
        #myBackground {
            -moz-opacity:.50;
            opacity:0.5;
        }
    }
    /* and IE last so it doesn't blow up */
    #myBackground {
        opacity:.50;
        filter:alpha(opacity=50);
        filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0.5);
    }
    

    I may have redundancies in the above code -- if anyone wishes to clean it up further, feel free!

提交回复
热议问题