How Do You Get One Image to Change to Another When Hovered Over?

Discussion in 'HTML & Website Design' started by Masterful, Apr 12, 2008.

  1. #1
    How can I get one image to change to another one when someone hovers over the first image? What kind of CSS code do I use? For example, say I created menu buttons for my site and wanted the buttons to change in colour when hovered over. How can I do this?

    Any help will be highly appreciated.
     
    Masterful, Apr 12, 2008 IP
  2. meaghannf

    meaghannf Well-Known Member

    Messages:
    275
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    110
    #2
    This is the code I use:

    In that example, the image is a link, and has a set and hover over image as well.
     
    meaghannf, Apr 12, 2008 IP
  3. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You could set the menu buttons to block and then have them change on hover for example:

    menu li a { display:block ; background-colour:#000;}
    menu li a:hover { display:block ; background-colour:#FFF;}

    I haven't tested it on images to be honest but i know it works for background colours.
     
    wd_2k6, Apr 12, 2008 IP
  4. georgen2u

    georgen2u Active Member

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #4
    thats a bunch of code man its pretty easy. dont you have Dreamweaver or you can use a text editor like note pad to do it . but for saty sake you can use dreamweaver probbly Firworks because it does it perfectly
     
    georgen2u, Apr 12, 2008 IP
  5. ezcat

    ezcat Peon

    Messages:
    233
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    What?
    menu li a { display:block ; background-colour:#000;}
    menu li a:hover { display:block ; background-colour:#FFF;}
    will work fine!
     
    ezcat, Apr 12, 2008 IP
  6. Masterful

    Masterful Well-Known Member

    Messages:
    1,653
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #6
    Thanks for the responses, guys. However, I think I confused everyone with my above example. I don't want just the colour to change when an image is hovered over; I want the complete image to change to another of exactly the same proportions. I think Meaghannf's response was the closest to what I'm looking for, but I don't understand the code that s/he presented:

    Where do I put the first image's source and the second image's source? And is all of that code really required? It looks like a whole lot of code for such a simple function!

    Does anyone know how to do it with simple CSS?
     
    Masterful, Apr 12, 2008 IP
  7. meaghannf

    meaghannf Well-Known Member

    Messages:
    275
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    110
    #7
    Sorry for the confusion, I just cut and paste my source code. Let me see if I can clarify a little:

    The ONLY things in that code you change are OriginalImage.IMG and MouseOverImage.IMG to the correct image paths.

    Yeah, I realize what I said before was completely unhelpful. Sorry, this should be better :).
     
    meaghannf, Apr 12, 2008 IP
  8. pioneer1

    pioneer1 Peon

    Messages:
    1,137
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks for the script. Works well
     
    pioneer1, Apr 12, 2008 IP
  9. Masterful

    Masterful Well-Known Member

    Messages:
    1,653
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #9
    Thanks, Meaghannf! I appreciate your clarification. I will try your code and see what happens. And thank you to everyone else that contributed. :)
     
    Masterful, Apr 13, 2008 IP
  10. meaghannf

    meaghannf Well-Known Member

    Messages:
    275
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    110
    #10
    No problem, let me know if you're still having problems :).
     
    meaghannf, Apr 13, 2008 IP