How can I make my website's background transparent without making the content (images & text) transparent too?

前端 未结 8 1381
小鲜肉
小鲜肉 2020-12-15 04:25

I\'m doing a website for a school project, and I\'m currently having a small problem... I can\'t make the body\'s background transparent without it also affecting the conten

8条回答
  •  半阙折子戏
    2020-12-15 05:18

    I think the simplest solution, rather than making the body element partially transparent, would be to add an extra div to hold the background, and change the opacity there, instead.

    So you would add a div like:

    And move your body element's background CSS to it, as well as some additional positioning properties, like this:

    #background {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-image: url('images/background.jpg');
        background-repeat: no-repeat;
        background-attachment: fixed;
        background-size: 100%;
        opacity: 0.8;
        filter:alpha(opacity=80);
    }
    

    Here's an example: http://jsfiddle.net/nbVg4/4/

提交回复
热议问题