Display Image On Text Link Hover CSS Only

后端 未结 6 1519
感情败类
感情败类 2020-12-13 05:53

I have a text link. When the user hovers over the text link, I want an image to be displayed elsewhere on the page. I want to do this using css. I thought it could be done s

相关标签:
6条回答
  • 2020-12-13 05:58

    I did something like that:

    HTML:

    <p class='parent'>text text text</p>
    <img class='child' src='idk.png'>
    

    CSS:

    .child {
        visibility: hidden;
    }
    
    .parent:hover .child {
        visibility: visible;
    }
    
    0 讨论(0)
  • 2020-12-13 05:59

    add

    .hover_img a:hover span {
        display: block;
        width: 350px;
    }
    

    to show hover image full size in table change 350 to your size.

    0 讨论(0)
  • 2020-12-13 06:01

    It can be done using CSS alone. It works perfect on my machine in Firefox, Chrome and Opera browser under Ubuntu 12.04.

    CSS :

    .hover_img a { position:relative; }
    .hover_img a span { position:absolute; display:none; z-index:99; }
    .hover_img a:hover span { display:block; }
    

    HTML :

    <div class="hover_img">
         <a href="#">Show Image<span><img src="images/01.png" alt="image" height="100" /></span></a>
    </div>
    
    0 讨论(0)
  • 2020-12-13 06:07

    From w3 schools:

    <style>
    /* Tooltip container */
    .tooltip {
      position: relative;
      display: inline-block;
      border-bottom: 1px dotted black; /* If you want dots under the hoverable text */
    }
    
    /* Tooltip text */
    .tooltip .tooltiptext {
      visibility: hidden;
      width: 120px;
      background-color: black;
      color: #fff;
      text-align: center;
      padding: 5px 0;
      border-radius: 6px;
    
      /* Position the tooltip text - see examples below! */
      position: absolute;
      z-index: 1;
    }
    
    /* Show the tooltip text when you mouse over the tooltip container */
    .tooltip:hover .tooltiptext {
      visibility: visible;
    }
    </style>
    
    <div class="tooltip">Hover over me
      <img src="/pathtoimage" class="tooltiptext">
    </div>
    

    Sounds like about what you want

    0 讨论(0)
  • 2020-12-13 06:19

    It is not possible to do this with just CSS alone, you will need to use Javascript.

    <img src="default_image.jpg" id="image" width="100" height="100" alt="" />
    
    
    <a href="page.html" onmouseover="document.images['image'].src='mouseover.jpg';" onmouseout="document.images['image'].src='default_image.jpg';"/>Text</a>
    
    0 讨论(0)
  • 2020-12-13 06:24

    CSS isn't going to be able to call other elements like that, you'll need to use JavaScript to reach beyond a child or sibling selector.

    You could try something like this:

    <a>Some Link
    <div><img src="/you/image" /></div>
    </a>
    

    then...

    a>div { display: none; }
    a:hover>div { display: block; }
    
    0 讨论(0)
提交回复
热议问题