2
     html{ 
            background: url('web-design.jpg') no-repeat center center fixed; 
            -webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;
        }  

I am using this CSS above to display a background image for my web page. However, the image is a little in the way of the text that I want to display on the webpage.

If I change its opacity, however, all will be fine. I tried using the opacity : 0.5 in the above CSS but that did not help. How can I change the opacity of this background image ?

What I also tried was making a wrapper <div> and setting its background image and opacity. That did not help, either.

My html:

<body>
        <div class="parent">
            <div class="content">
                <p id="dollar">$</p>
                <p id="name">variableName</p>
                <p id="equals"> = </p>
                <p id="value"> someValue </p>
            </div>
        </div>
</body>  

My css:

@font-face{
            font-family: "RobotoCondensed-Regular";
            src : url("RobotoCondensed-Regular.ttf");
        }

        body, html{
            height : 100%;
        }


        body:after{
            z-index:-1;
            background: url('web-design.jpg') no-repeat center center fixed; 
            -webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;
            position: absolute;
            left:0;
            top:0;
            right:0;
            bottom:0;
            opacity:1;
        }

        .parent{
            height : 100%;
            display : flex;
            display : -webkit-flex;
            display : -moz-flex;
            display : -o-flex;
            align-items: center;
            justify-content: center;
        }
        .content{
            display : flex;
            display : -webkit-flex;
            display : -moz-flex;
            display : -o-flex;
            align-items: center;
            justify-content: center;
            background-color : rgba(,,,0.5);
            border-radius : 10%;
        }
        p{
            font-family : "RobotoCondensed-Regular";
            font-size : 32px;
        }
0

3 Answers 3

2

Try this:

http://jsfiddle.net/WSEXC/

body {
    position: relative;
}

body:before
{
    content: "";
    z-index:-1;
     background: url(http://www.placehold.it/1200x800) no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    position: absolute;
    left:0;
    top:0;
    right:0;
    bottom:0;
    opacity:0.2;
}
Sign up to request clarification or add additional context in comments.

3 Comments

I am using flexbox model. Will your code be OK with that ?
Try it. I don't think this will get in your way, what so ever
@LittleChild it ist just 20% visibile maybe tune this value up. Also see the CSS in the JSfiddle: body {height:100%}
2
html {
   position: relative;
}
html:after {
            background: url('web-design.jpg') no-repeat center center fixed; 
            -webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;
            position: absolute;
            opacity: 0.5; 
            filter: alpha(opacity=50);
}

I think this should work.

Comments

2

Here is the working Demo. http://jsbin.com/payixipa/1/

body {
  width: 500px;
  height: 500px;
  display: block;
  position: relative;
}
body:after{ 
   content: " ";
    position: absolute;
  z-index: -1; 
    top: 0;
  left: 0;
  bottom: 0;
  right: 0;
background: url('http://lorempixel.com/400/400') no-repeat; 
-webkit-background-size: cover;
 -moz-background-size: cover;
 -o-background-size: cover;
 background-size: cover;
 -moz-opacity:.50; 
  -webkit-opacity:.50; 
 -ms-filter:"alpha(opacity=50)";
  filter:alpha(opacity=50);
  filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0.5);
  opacity:.50; 
        } 

1 Comment

I can see the text in center. here is the link you can check as well. jsbin.com/payixipa/2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.