开发者

CSS tooltip on image problem

I've got a problem with a CSS tooltip over an image. Using it on text works fine, however when I use an image instead of text, it seems to be having issues, the issues are a bit hard to explain so I'll just give you a link: http://zorps.dk/css-tooltips/tooltip.html

CSS code:

.tooltip {
        border-bottom: 1px dotted #000000; color: #000000; outline: none;
        cursor: help; text-decoration: none;
        position: relative;
    }
    .tooltip span {
        margin-left: -999em;
        position: absolute;
    }
    .tooltip:hover span {
        border-radius: 5px 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px; 
        box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.1); -webkit-box-shadow: 5px 5px rgba(0, 0, 0, 0.1); -moz-box-shadow: 5px 5px rgba(0, 0, 0, 0.1);
        font-family: Calibri, Tahoma, Geneva, sans-serif;
        position: absolute; left: 1em; top: 2em; z-index: 99;
        margin-left: 0; width: 250px;
    }
    .tooltip:hover img {
        border: 0; margin: -10px 0 0 -55px;
        float: left; position: absolute;
    }
    .tooltip:hover em {
        font-family: Candara, Tahoma, Geneva, sans-serif; font-size: 1.2em; font-weight: bold;
        display: block; padding: 0.2em 0 0.6em 0;
    }
    .classic { padding: 0.8em 1em; }
    * html a:hover { background: transparent开发者_运维问答; }
    .classic {background: #FFFFAA; border: 1px solid #FFAD33; }

html code:

<p>     <a class="tooltip" href="#"> <img src="icon_question.png" /> <span class="classic">The tooltip text goes here!</span></a></p>

Anyone know what the issue is? Thanks!

Note: the code is taken from: http://sixrevisions.com/css/css-only-tooltips/


It's the code within the .tooltip:hover img class - If you remove it, it works well:

http://jsfiddle.net/RyRRM/


it's probably because the event is triggered by the tooltip's non-text-node parent. When you hover over the image, it detects a mouseout event for the parent. You could try making the image a css background and setting the width of the element instead of embedding the <img>

Your markup could then be

<a class="tooltip image" href="#"><span class="classic">The tooltip text goes here!</span></a>

and your css would be

.tooltip.image {
    width: 12px;
    height: 14px;
    background-image: url("./icon_question.png");
    display: block;
    background-repeat: no-repeat;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜