Reputation: 423
I have a problem with background:
#nth_image
ID..background-gradient
class.The problem is that background-image overwrite background gradient.
.background_gradient {
background: -webkit-radial-gradient(top, ellipse cover, #f9f9f9 0%,#eaeaea 100%);
}
#first_image {
background: url(images/img01.png);
}
#second_image {
background: url(images/img02.png);
}
#third_image {
background: url(images/img03.png);
}
<div class="parent">
<div id="first_iamge" class="background_gradient"></div>
<div id="second_image" class="background_gradient"></div>
<div id="third_image" class="background_gradient"></div>
</div>
Upvotes: 1
Views: 127
Reputation: 3397
If you want to mix 2 types of background on a single element, my suggestion is to use css pseudo element.
You could use the before
pseudo element having the same size as your element for your gradient part.
You could have something like this:
.background_gradient {
position: relative;
}
.background_gradient:before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index:-1;
background: -webkit-radial-gradient(top, ellipse cover, #f9f9f9 0%,#eaeaea 100%);
}
#first_image {
background: url(images/img01.png);
}
#second_image {
background: url(images/img02.png);
}
#third_image {
position: relative;
background: url(images/img03.png);
}
Upvotes: 0
Reputation: 2032
Both the gradient and image background utilize the same image property of the background. Its as if you are writing it like this:
.class {
background-image: url('/path/to/image.png');
background-image: -webkit-radial-gradient(top, ellipse cover, #f9f9f9 0%,#eaeaea 100%);
}
so basically you are overwriting the image part of the background with the gradient or vice versa depending on which rule takes precedence over the other.
My suggestion would be to style your markup differently. Have a div inside of the div with the background you want.
<div class="background-gradient">
<div id="first-background"></div>
</div>
Upvotes: 1