[Javascript] Re: background img dimensions

Innerlab innerlab at hotmail.com
Sat Sep 4 10:30:07 CDT 2004


Now I typed the right subject :)  Before I just replied to an older post,  but I forgot to rewrite the subject line.

> > document.write('<img src="'+jsPath +'" width="'+jsHeight +'" height="+jsWidth +" />');
> > Now, how can I change such parameters when the image it's used as a background
> > Any ideas?

Hassan:

> 2/ the CSS spec is your friend; it shows the standard properties
>     available through the DOM -- <http://www.w3.org/TR/CSS21/>;
>     in this case, background images don't have a height and width
>     property, if you were looking for those specifically

Yes, that feature would be nice to have...

Flavio:

>document.write('div.mydiv {background-image:url('+jsPath +');}');

Yes, the background URL in my code is dynamic through JavaScript, but the height and width of that image cannot be specified.
However, the container block (<div> in this case) can force that image to change dimension.

Like Paul wrote:

>  <div style="background-image: url('frogs.jpg'); height: 100px; width: 200px;">        </div>

The problem here is that my image has to be repeated along X, and the height is dynamic.
It seems to me that specific <div> height doesn't work when the bkg. image is repeated. The <div> itself changes height, but the
background image stays at its original height.  I dunno....

I just joined a CSS list, because the solution to my problem lies on those <div> parameters, but so far it seems that I cannot get
the results I want.... Thanks for the replies, guys







More information about the Javascript mailing list