| 10:07 pm on Jun 21, 2011 (gmt 0)|
How are you setting the background-image to begin with?
| 10:30 pm on Jun 21, 2011 (gmt 0)|
The background image is set like this:
|<div style="background-image: bgimage.php; background-repeat: no-repeat;"> |
DIV CONTENTS GO HERE
the PHP file is generating a background image, which will have different dimensions every time.
| 11:20 pm on Jun 21, 2011 (gmt 0)|
The CSS doesn't know how big the background is. Foreground, of course, would be no problem: unless you tell it otherwise, the container will expand to fit what it's holding. If only our clothes, garages and toolboxes could do the same :(
| 11:29 pm on Jun 21, 2011 (gmt 0)|
The range of image sizes is not completely out of my control, but it is too large of a range to simply set the div size to the highest possible value. Plus, sometimes there will be no background image at all, and the div simply needs to contain its contents.
| 11:31 pm on Jun 21, 2011 (gmt 0)|
correction on the snippet I posted earlier, should say:
| 11:54 pm on Jun 21, 2011 (gmt 0)|
If my understanding is right, you can also do this:
<img src="<?php ....; ?>" alt="" style="position: absolute;"/>
<div style="position: relative;">CONTENT HERE</div>
And maybe some padding on the CONTENT AREA.
| 9:23 am on Jun 22, 2011 (gmt 0)|
May be a background-image isn't the correct tool here and an absolutely positioned IMG (positioned behind other content), as in @pokra's solution would be better? This could be altered to simply:
<img src="bgimage.php" alt="" style="position: absolute;">
Which doesn't rely on the actual page being rendered by PHP.
(2) Or, may be... load the image in a hidden IMG element (nothing is currently set as the background-image of the DIV container). Get the dimensions of this image (as above) and then set the dimensions AND background-image of your DIV container to the same as the IMG element. Not that this is possible though?