I want to create an html page with a watermark. I set the background-image on the body. However I have some elements that are not allowing the background image to bleed through. They define their own background-color (but not background-image), overriding the color in the body. This surprised me. They didn’t override the image, just the color.
It seems reasonable to have a visible watermark on a page with elements having different background colors.
How do I get the effect I want using standard html/css?
Here’s some sample code that shows the problem. Note the white block obscuring my watermark image.
<html> <head> <style type='text/css'> .everything { background: url(/images/shield-25.png) blue no-repeat center; } table, div{ width: 100% } #table2 { background-color: white } #div2 { background-color: white } </style> </head> <body class='everything'> <table id='table1'><tr><td>Top</td></tr></table> <!-- This table put a big white line over my watermark image. --> <table id='table2'><tr><td>Middle</td></tr></table> <table id='table3'><tr><td>Bottom</td></tr></table> <div id='div1'><tr><td>Top</td></tr></div> <!-- Thought maybe it was a table thing but nope, divs do it too. --> <div id='div2'><tr><td>Middle</td></tr></div> <div id='div3'><tr><td>Bottom</td></tr></div> </body> </html>
Unfortunately for you, this is the intended behavior.
background-imageandbackground-colorare sub-properties of thebackgroundproperty. Since you defined a background on#table2and#div2, you can’t see ‘through’ them to the page background anymore.CSS3 allows you to set the opacity of the background using the
rgba()expression, but IE doesn’t support this (Firefox 3 and Safari/Webkit do). To get an rgba()-like effect in IE, you can use afilter:rule such as the following:Note how the
startColorstrandendColorstrparameters have a fourth value for alpha.