DEMO
a.tooltip span {
z-index:2;
display:none;
padding:14px 20px;
width:inherit;
line-height:16px;
position: relative;
}
a.tooltip {
position: relative;
}
a.tooltip:hover span{
display:inline;
position:absolute;
border:1px solid #DCA;
background:#FF4747;
left: 0px;
bottom: 15px;
font-weight: bold;
}
要調整較小的屏幕寬度,可以使用媒體查詢:
@media (max-width: 480px) {
a.tooltip:hover span{
display:inline;
position:absolute;
border:1px solid #DCA;
background:#FF4747;
left: -30px;
bottom: 18px;
font-weight: bold;
}
}
對於非常敏感的定位:
$(".tooltip").hover(function() {
var height = $(this).find('span').height();
var top = $(this).offset().top;
if(height > top){
$(this).find('span').css("top","10").css("bottom","inherit");
} else if(height < top) {
$(this).find('span').css("bottom","10").css("top","inherit");
}
});
添加上面的代碼在你的JS
嘗試使用媒體查詢。 http://css-tricks.com/css-media-queries/ – nej
@shin。我不介意爲此而努力。但瀏覽器兼容性是一個問題,因爲我的項目主要關注IE。 –