views:

45

answers:

2

Is there a way to take a DIV that has a background image on it, then apply a CSS3 gradient on it to simulate a lightsource?

The reason I ask was because I was thinking of making the BODY tag on a page use a repeating background pattern, apply the CSS3 gradient lightsource on it, and then stick a white DIV on top of that where all the page content would go.

For those without CSS3, it would degrade nicely into just a white DIV on top of a repeating background.

A: 

I don't thinkn there is any way at it can be done but you could add a div right after your tag that is 100% by 100% with a low z-index and apply the CSS3 to that.

I hope this is what you are talking about.

Taylor Satula
+2  A: 

To do this just on the body element you'll have to combine multiple backgrounds, RGBA and radial gradients. You'll need a default property with a single repeating background for those browsers that don't support gradients, then Gecko and Chrome/Safari have different syntax for the gradients so you'll need a property each for them. Should end up with something like (untested):

body {
    background: url(repeat.jpg);
    background: -moz-radial-gradient(100px 100px, ellipse farthest-corner,   white 0%, rgba(255, 255, 255, 0) 100%, rgba(255, 255, 255, 0.5) 25%) no-repeat, url(repeat.jpg);
    background: -webkit-gradient(radial, 100 100, 200, from(#fffff), to(rgba(255, 255, 255, 0)), color-stop(25%, rgba(255, 255, 255, 0.5)) no-repeat, url(repeat.jpg);
}

You may find adding a wrapper element for your lightsource is less effort in the long run.

robertc
Good catch; I'd forgotten about multiple backgrounds...and was all set to say 'no' and so forth. =) +1
David Thomas
I tried this in FF3.6.3 and didn't see any difference. So I commented out the bottom two lines and refreshed -- same appearance.
Volomike
Sorry, the 'top' background image has to come first in the list, changed that. I'll just restate: I haven't tested the above code, you'll probably need to fiddle things around to get it to work. The links should help.
robertc
I'm getting it to work. I had to apply background image to BODY, and then create a DIV set to size of page and then apply the radial gradient. It's working.
Volomike