CSS: Translucent Background and Image

body {
  background-image: url('cloud.png');
  background-color: rgba(255, 255, 255, 0.6);
}

I tried using the above to create a translucent white background over the background image. It does not work, only the background image is displayed, and the background color is ignored. How to adjust the opacity of the background image of the body?

+4
source share
3 answers

background-colorIt is placed under background-image, not above it (when rendering in a web browser). To place a translucent white block on top of the image, you need to place another other HTML element on top of it with background-color.

+2
source

- css "before", DOM. z-index: -1, :

body {
    background: url("image.jpg");
}
body:before {
    content: "";
    display: block;
    position: fixed;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    z-index: -1;
    background-color: rgba(255, 255, 255, 0.6);
}

jsfiddle

+14

, . - , - , , . div, , Position: relative, : .

HTML:

<div class="tempsale" >
    <img src="images/ULR FOR YOUR BANNER GOES HERE.jpg" width="800" height="100" border="0" alt="banner">
    <div class="tempsaletext">
        <img src="images/URL FOR YOUR TEMPORARY SALE GOES HERE.jpg" width="500px" height="80px" alt="Sale">
    </div>
</div>

CSS:

.tempsale {
    text-align:center; 
    position:relative;
}
.tempsaletext {
    positon:absolute; 
    top:10px; 
    left:20%; 
}

. .

0

All Articles