EDIT: Extremely important thing I forgot to mention, I can't edit the base html, only the css. This is for a reddit stylesheet.
I want to have a semi-transparent color background over an image background as a tint. Here's what I've tried: This just shows the image:
background: url(image) no-repeat, rgba(0,0,0,0.5);
This shows the image and breaks its scaling (background-size: 100%;):
background: rgba(0,0,0,0.5), url(image) no-repeat;
This makes the background entirely black, with the transparency fading to whatever's behind it instead of the image:
background-image: url(image) no-repeat;
background: rgba(0,0,0,0.5);
This once again shows just the image, and breaks the scaling:
background-image: url(image) no-repeat;
background-color: rgba(0,0,0,0.5);
This shows just the image without breaking the scaling:
background: url(image) no-repeat;
background-color: rgba(0,0,0,0.5);
I tried using @Trevan 's answer with no luck too:
#header:lang(dd) {
position: relative;
background: url(%%HexBackground%%) no-repeat;
}
#header:lang(dd)::before {
position: absolute;
content: "";
top: 0;
left: 0;
background: rgba(0,0,0,0.5);
}
I'm probably doing it wrong though.
Might not be applicable depending on what exactly you want to do (suggest JSFiddle) but you should have a look at SVG filters:
http://www.html5rocks.com/en/tutorials/filters/understanding-css/
CSS-only:
box-shadow
See a basic example here http://jsfiddle.net/vyo168gg/1/
Basically, instead of having the box shadow showing on the outside of the element, we put it on the inside.
The trick is to have the first or second parameter(?) to be larger than the elements width/height so that it overlaps the whole image.
What I would probably do is use a pseudo element positioned absolutely on top of the element with the background.
Overlay a div on top of your image, maybe something like this?
HTML
CSS
JSFIDDLE
What you need to do is separate the transparency from the background. Doing something like following should work:
HTML
<div class="background"> <div class="tint"></div> </div>
CSS
You can use a color and opacity for the tint, but not all browsers acknowledge that property(IE8).
Something like this?
What we're doing here is using an
:after
pseudo element to give you the desired effect of having an overlaid image tint without muddying up the DOM.The benefits to doing it this way as opposed to others are
Enjoy!