Display text on MouseOver for image in html

前端 未结 4 1834
春和景丽
春和景丽 2020-12-02 08:16

I would like to display text when the user mouseovers the image.

How can I do this in HTML/JS?

相关标签:
4条回答
  • 2020-12-02 08:48

    You can do like this also:

    HTML:

    <a><img src='https://encrypted-tbn2.google.com/images?q=tbn:ANd9GcQB3a3aouZcIPEF0di4r9uK4c0r9FlFnCasg_P8ISk8tZytippZRQ' onmouseover="somefunction();"></a>
    

    In javascript:

    function somefunction()
    {
      //Do somethisg.
    }
    

    0 讨论(0)
  • 2020-12-02 08:50

    You can use CSS hover in combination with an image background.

    CSS

       .image
    {
        background:url(images/back.png);
        height:100px;
        width:100px;
        display: block;
        float:left;
    }
    
    .image  a {
        display: none;
    }
    
    .image  a:hover {
        display: block;
    }
    

    HTML

    <div class="image"><a href="#">Text you want on mouseover</a></div>
    
    0 讨论(0)
  • 2020-12-02 08:56

    You can use title attribute.

    <img src="smiley.gif"  title="Smiley face"/>
    

    You can change the source of image as you want.

    And as @Gray commented:

    You can also use the title on other things like <a ... anchors, <p>, <div>, <input>, etc. See: this

    0 讨论(0)
  • 2020-12-02 09:00

    You can use CSS hover
    Link to jsfiddle here: http://jsfiddle.net/ANKwQ/5/

    HTML:

    <a><img src='https://encrypted-tbn2.google.com/images?q=tbn:ANd9GcQB3a3aouZcIPEF0di4r9uK4c0r9FlFnCasg_P8ISk8tZytippZRQ'></a>
    <div>text</div>
    ​
    

    CSS:

    div {
        display: none;
        border:1px solid #000;
        height:30px;
        width:290px;
        margin-left:10px;
    }
    
    a:hover + div {
        display: block;
    }​
    
    0 讨论(0)
提交回复
热议问题