我正在检测文本显示的时间太长,所以如果它很长,我使用CSS缩小它们,并放置一个包含整个文本的工具提示,但如果时间不长,请将其设置为绿色。 Ocurres如下:我如何指定工具提示的正确位置?
它把在完全文本的中心,而不是在短路的文本。我怎么能放在中心,但在短文本,而不是在长文本?
如果你想我所有的代码,它在这里:
$(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip();
});
$(function() {
$('.txt').each(function(i) {
if (isEllipsisActive(this)) {
$(this).attr("data-original-title", $(this).text());
} else $(this).css({
'color': 'green'
});
});
});
function isEllipsisActive(e) {
return (e.offsetWidth > 95);
}
.demo {
max-width: 95px;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container">
<h3>Tooltip Example</h3>
<div class="demo">
<a class="txt" href="#" data-toggle="tooltip" data-placement="top">Hover over meeeeeeeeeeeeeeee</a>
</div>
<div class="demo">
<a class="txt" href="#" data-toggle="tooltip" data-placement="top">Hover over meeeeeeeeeeeeeeee</a>
</div>
</div>
很好,谢谢!另一个代码,看着这个“a [data-toggle]:hover:after {left:50px;}”,它放在50px中,在你的例子中居中,因为“a”是100px,但是如果发生了什么我增加“a”的宽度?我怎么能检测到“a”的一半,并把它放在左css属性?感谢您的时间 –
我说因为我制作的应用程序可以显示一切响应,并且您知道每个设备的尺寸都不相同。再次感谢:') –
@ChristopherCoriaVásquez,您不用担心,因为它可以使用jvascript,但简单的方法是使用'left:0px'作为所有状态。 – Ehsan