Results 1 to 4 of 4

Thread: How to rollover another image on my current image by CSS

  1. #1
    Join Date
    Dec 2009
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How to rollover another image on my current image by CSS

    I have 2 different images:
    meobay.gif
    and
    thankyou.gif
    My problem is when an user move his mouse over the image of meobay.gif, my code can not change meobay.gif to thankyou.gif

    Please help me out with my code:

    HTML:
    <div id="rightCV">
    <a href="Doc/WebDeveloper.pdf"><img src="CSS/images/meobay.gif"/></a>
    </div>
    CSS:
    #rightCV{
    position: absolute;
    right: 270px;
    margin-top:87px;
    }
    img {
    width:230px;
    height:170px;
    border: none;
    background-repeat:no-repeat;
    }
    img:hover{
    background-image: url(images/thankyou.gif);
    border: none;
    }

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    Try using a div with a background image instead;

    Code:
    <style type="text/css">
    div#mypic a {
    width:280px;
    height:300px;
    background: url("meobay.gif") 0 0 no-repeat; 
    }
    div#mypic a:hover { 
    background: url("thankyou.gif") 0 0 no-repeat; 
    }
    </style>
    Code:
    <div id="rightCV">
    <div id="mypic"><a href="Doc/WebDeveloper.pdf"></a></div>
    </div>
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Dec 2009
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    thank you for your advise, unfortunately, it is not working and there is not any pic after I applied the code

    <div id="rightCV">
    <div id="mypic"><a href="Doc/WebDeveloper.pdf"></a></div>
    </div>
    #rightCV {
    position: absolute;
    right: 230px;
    margin-top:87px;
    }
    #mypic a {
    width:280px;
    height:300px;
    background: url("images/meobay.gif") 0 0 no-repeat;
    }
    #mypic a:hover {
    background: url("images/thankyou.gif") 0 0 no-repeat;
    }

  4. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    I tested the code and it works fine for me - try checking the paths and/or use absolute references.

    Also try adding positioning elements into the CSS for the image;
    Code:
    position: absolute;
    top: 0px;
    left: 0px;
    My test page;
    Code:
    <html>
    <head>
    <title>Image Swop</title>
    <style type="text/css">
    div#mypic a {
    width:300px;
    height:280px;
    background: url("http://img837.imageshack.us/img837/4831/meobay.gif") 0 0 no-repeat; 
    }
    div#mypic a:hover { 
    background: url("http://img258.imageshack.us/img258/6564/thankyouo.gif") 0 0 no-repeat; 
    }
    </style>
    </head>
    <body>
    <div id="rightCV">
    <div id="mypic"><a href="Doc/WebDeveloper.pdf"></a></div>
    </div> 
    </body>
    </html>
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

Bookmarks

Posting Permissions

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