• Advertisement
Sign in to follow this  

[web] using css to change source image

This topic is 4663 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

is something like this possible?
<html>
<head>
	<style>
	#image
	{
		src: url(gfk_money_over.gif);
	}
	</style>
</head>

<body>
	<img id="image" />
</body>
</html>

Share this post


Link to post
Share on other sites
Advertisement
You can't do something like this in CSS. You'll need javascript to do the job:

document.getElementById('image').src = "gfk_money_over.gif";

Share this post


Link to post
Share on other sites
Looks to me like you could just create a div with the desired image as a background, but I'm not seeing the advantage of that, as it still isn't dynamic.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kazgoroth
Looks to me like you could just create a div with the desired image as a background, but I'm not seeing the advantage of that, as it still isn't dynamic.
You can do this with the image tag as well, as long as you give it an invisible gif or png as a source. Still strange, perhaps the OP could try and explain why he's doing things this way.

Share this post


Link to post
Share on other sites
the reason is because my html is dynamic whereas my css is not.
and because this is for a menu, one of the table entries already uses a background image, whereas the header and footer for the table do not.

generate_menu("menu","menu-header.png","menu-footer.png",$linkslist);

td.menuitems
{
background-image: url(menu-bg.png);
}


as you can see I want to keep the data in one place (either css file or menu arguments).

using an empty div tag doesn't work, and you also need a fixed image size for transparent image.

it doesn't matter any more though because I've simply inlined the above css data inside the generate_menu function.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement