CSS: image link, change on hover

前端 未结 8 2134
故里飘歌
故里飘歌 2020-11-29 17:48

I have an image that is a link. I want to show a different image when the user hovers over the link.

Currently I\'m using this code:



        
相关标签:
8条回答
  • 2020-11-29 18:47

    That could be done with <a> only:

    #twitterbird {
     display: block; /* 'convert' <a> to <div> */
     margin-bottom: 10px;
     background-position: center top;
     background-repeat: no-repeat;
     width: 160px;
     height: 160px;
     background-image: url('twitterbird.png');
    }
    #twitterbird:hover {
     background-image: url('twitterbird_hover.png');
    }
    
    0 讨论(0)
  • 2020-11-29 18:54

    If you have just a few places where you wish to create this effect, you can use the following html code that requires no css. Just insert it.

    <a href="TARGET URL GOES HERE"><img src="URL OF FIRST IMAGE GOES HERE" 
    onmouseover="this.src='URL OF IMAGE ON HOVER GOES HERE'"
    onmouseout="this.src='URL OF FIRST IMAGE GOES HERE AGAIN'" /></A>
    

    Be sure to write the quote marks exactly as they are here, or it will not work.

    0 讨论(0)
提交回复
热议问题