我不知道如何解決你使用的工具提示創建方法中的問題,但我想出另一種確實提供了一個完全可定製的工具提示的方法,也是在IE8 。它非常輕巧:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Demo Lightweight Tooltip CSS + JS</title>
<style>
html {
font-size: 62.5%;
}
body {
font: normal 1.3em Verdana;
padding-top: 2em; /* creates space for the first tooltip in this demo */
}
span.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dashed black;
}
span.tooltip:hover {
cursor: help;
}
span.tip {
position: absolute;
bottom: 20px;
left: 0px;
display: block;
width: auto;
white-space: nowrap;
font-size: .9em;
border: 0px solid black; /* change as desired */
border-radius: 6px;
padding: 1px 5px;
background: #eee;
background: linear-gradient(top, #eee, #ccc);
background: -moz-linear-gradient(top, #eee, #ccc);
background: -o-linear-gradient(top, #eee, #ccc);
background: -webkit-linear-gradient(top, #eee, #ccc);
background: -webkit-gradient(linear, left top, left bottom, from(#eee), to(#ccc));
background: -ms-linear-gradient(top, #eee, #ccc);
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr=#eeeeee,EndColorStr=#cccccc);
zoom: 1;
visibility: hidden;
}
</style>
</head>
<body>
<p>The <span class="tooltip">WHO<span class="tip">World Health Organization</span></span> was established in 1948.</p>
<p>
It is part of the
<span class="tooltip">UN
<span class="tip">United Nations, <br>the successor of the <br>League of Nations</span>
</span>,
which was established in 1945.
</p>
<script>
var tooltips = document.querySelectorAll('.tooltip');
for (var i=0; i<tooltips.length; i++) {
var tooltip = tooltips[i];
if ('ontouchstart' in window || window.navigator.msPointerEnabled) {
tooltip.onclick = function() {
if (this.children[0].style.visibility == '' || this.children[0].style.visibility == 'hidden')
this.children[0].style.visibility = 'visible';
else this.children[0].style.visibility = 'hidden';
}
}
else {
tooltip.onmouseover = function() {
this.children[0].style.visibility = 'visible';
}
tooltip.onmouseout = function() {
this.children[0].style.visibility = 'hidden';
}
}
}
</script>
</body>
</html>
這裏是現場演示:http://codepen.io/anon/pen/Aidcb?editors=100。
一對夫婦的側事項:
。
讓我知道你喜歡它,如果你願意。
試着把它的最大寬度和高度 – imbondbaby
在哪個div,我應該給最大寬度?我把它給了div#mcTooltip, 但它沒有幫助。除此之外,max-width應該類似於js文件中設置的javascript max-width屬性。否則,它不適合 – user1896653