这是我能做的最好的。唯一的限制是只能有一行文字。但是,您可以很容易地将其转换为执行一些不同的操作,例如生成一个内部为div的80%宽度的div,然后居中该div以允许使用段落文本。
JSBin示例在底部。
CSS
.vpbutton {
padding:4px;
background-color:#EFEFEF;
}
.userbox img{
padding:8px;
background-color:#EFEFEF;
border:1px solid #e5e5e5;
}
.userbox img:hover{
opacity:.2;
}
.hover-text {
display:none;
position:absolute;
}
.userbox img:hover ~ .hover-text {
border:1px solid #000;
top:0;
left:0;
display: block;
text-align:center;
}
JS
$(function() {
$('img[rel="hover-text"]').each(function() {
this$ = $(this)
console.log((this$.outerWidth() - this$.innerWidth()))
this$.parent().find('.hover-text').css({
'margin': (this$.outerWidth(true) - this$.width())+'px',
'top':0,
'left':0,
'height': (this$.height())+'px',
'width': (this$.width())+'px',
'line-height':(this$.height())+'px'
})
})
})()
HTML
<div class="userbox">
<img src='http://www.clonescriptsdb.com/scriptimages/inout-search-engine-google-like-search-engine-788.jpg' rel="hover-text">
<div class="hover-text">asd</div>
</div>
http://jsbin.com/azuyol/13/edit
UPDATE正确计算边距/填充/边框。
在IE6中使用jQuery将比CSS':hover'更好地支持。 – 2012-08-02 20:58:12
我们真的还在为IE6编码吗?我会建议忘记这一点,并希望这迫使用户升级(优先为非IE浏览器);-) – Pevara 2012-08-02 21:21:12