Search code examples
htmlcssdrop-down-menutooltipdropdown

I have a trouble with tooltip. It doesn't show up


Tooltip doesn't show up. I've tried to display it with
<span id="error-dropdown">Here is error text</span> and opacity property in CSS, but it doesn't display anyway. Link

<img src="https://symboldev.pp.ua/_data/error-sign.svg" alt="Error" id="error">
#error {
    height: 30px;
    width: 30px;
}

#error::after {
    content: "Here is the tooltip text";
    display: block;
    width: 300px;
    height: 300px;
    background: #555;

    position: absolute;
    visibility: hidden;
}

#error:hover::after {
    visibility: visible;
}

Solution

  • Here's a solution - just wrap a link around the image.

    #error {
    	height: 30px;
    	width: 30px;
    }
    
    #error::after {
      content: "Here is tooltip text";
      display: block;
      width: 300px;
      height: 300px;
      visibility: hidden;
    }
    
    #error:hover::after {
    	visibility: visible;
    }
    <a href="" id="error"><img src="https://symboldev.pp.ua/_data/error-sign.svg" alt="Error" id="error"></a>