View Full Version : onclick with CSS

02-22-2009, 08:06 PM
Is it possible to make an image change when you click on it? I'm editing my nav bar and I want the button to change only when I click on it. Is this possible with CSS?

02-22-2009, 08:22 PM
Hello cincinnatiboy4867,
I think a:active would change on the click and a:visited would keep it that way. Kind of an interesting idea, I've never tried it.

02-23-2009, 01:31 PM
Awesome it worked. Now I know this is probably not possible without Javascript but it would be cool. If you go here (http://durkmusicbeats.tripod.com/Copy_of_home.html) you can see that when you click the button goes down but it stays down even when you let go and move your mouse away. I know this is just an active change but is it possible to have it go back to normal when the mouse moves away at least.

I'm just experimenting... learning that's all. Trying to recreate the onclick command in Javascript with CSS.

I'm pretty sure you can't do this but hey, it's worth a try to ask some experts and see what they know (like Excavator)..


02-23-2009, 01:50 PM
You can’t. The link is active when you hold your mouse button down and it should become inactive as soon as you release the button. However, different browsers interpret this differently. In Firefox it works as intended but I think in IE the active state is persistent until the element loses its focus. JavaScript is the most cross-browser compatible method.

02-23-2009, 04:45 PM
That's what I figured... Thanks :)