Question

I have some <div>s with background-images and white text. I want to put a dark gradient on top of the image so that the white text will be readable. I must do this in CSS. How can I accomplish this?

<div><p>Here is some text</p><div>

div p {
    color: white;
}
div {
     background-image: url("images.png")
}
Was it helpful?

Solution

change this....

div {
     background-image: url("images.png")
}

to this...

div {
     background-image: linear-gradient(rgba(0,0,0,0.6),rgba(0,0,0,0.2)), url("images.png")
}

have a look on google for examples because quite a few browsers still need specific prefixes for linear-gradient because of varying browser specifications and implications.

OTHER TIPS

You can put the gradient as the background of the p element:

div p {

color:white;

background:linear-gradient(to bottom, rgba(252,255,244,.5) 0%,rgba(179,190,173,.5) 100%);

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top