Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Nov 2008
    Posts
    317
    Thanks
    159
    Thanked 0 Times in 0 Posts

    onclick with CSS

    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?

  • #2
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    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.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • Users who have thanked Excavator for this post:

    cincinnatiboy4867 (02-23-2009)

  • #3
    Regular Coder
    Join Date
    Nov 2008
    Posts
    317
    Thanks
    159
    Thanked 0 Times in 0 Posts

    Smile

    Awesome it worked. Now I know this is probably not possible without Javascript but it would be cool. If you go here 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)..


  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,790
    Thanks
    6
    Thanked 1,022 Times in 995 Posts
    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.

  • Users who have thanked VIPStephan for this post:

    cincinnatiboy4867 (02-23-2009)

  • #5
    Regular Coder
    Join Date
    Nov 2008
    Posts
    317
    Thanks
    159
    Thanked 0 Times in 0 Posts
    That's what I figured... Thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •