【发布时间】:2015-05-25 21:18:58
【问题描述】:
我有以下页面使用我无法正确定位的引导工具提示 该页面具有以下特点:
-
#outer-container是我的页面。它有固定的宽度。 - 有很多
.inner-container。它们具有固定宽度和overflow-x: auto。 -
.inner-containers是动态生成的。 (不确定是否相关,所以下面的示例代码是静态的) - 在
.inner-containerdiv 中存在任意HTML,其中可能包含许多<img>标签 - 每个
<img>都有一个以alt文本作为标题的工具提示。 - 图片可以比
.inner-containerdiv 更宽
这里是sn-p,你可以在全页运行sn-p时看到问题。
$("#outer-container").tooltip({
selector: "img",
placement: "right",
title: function () { return $(this).attr("alt"); },
});
#outer-container
{
border: 1px solid;
padding: 10px;
width: 960px;
margin-left: auto;
margin-right: auto;
overflow: auto;
}
.inner-container
{
width: 600px;
overflow-x: auto;
border: 1px solid;
margin-bottom : 10px;
float: right;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<div id="outer-container">
<div class="inner-container">
<figure>
<img src="http://i.imgur.com/mrXWW8S.png" alt="Man ALL IS LOŚ͖̩͇̗̪̏̈́T ALL IS LOST the pon̷y he comes he c̶̮omes he comes the ichor permeates all MY FACE MY FACE ᵒh god no NO NOO̼OO NΘ stop the an*̶͑̾̾̅ͫ͏̙̤g͇̫͛͆̾ͫ̑͆l͖͉̗̩̳̟̍ͫͥͨe̠̅s ͎a̧͈͖r̽̾̈́͒͑e not rè̑ͧ̌aͨl̘̝̙̃ͤ͂̾̆ ZA̡͊͠͝LGΌ ISͮ̂҉̯͈͕̹̘̱ TO͇̹̺ͅƝ̴ȳ̳ TH̘Ë͖́̉ ͠P̯͍̭O̚N̐Y̡ H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝S̨̥̫͎̭ͯ̿̔̀ͅ" />
<figcaption>
Image originally posted by <a href="http://meta.stackexchange.com/questions/213769/work-is-hard-lets-color-the-walls/213975#213975">Travis J</a>
</figcaption>
</figure>
</div>
<div class="inner-container">
<figure>
<img src="http://i.stack.imgur.com/CThCe.png" alt="Sanely-sized stackoverflow logo" />
<figcaption>Sanely-sized stackoverflow logo</figcaption>
</figure>
</div>
<div class="inner-container">
<figure>
<img src="http://i.stack.imgur.com/MvHsz.jpg" alt="Insanely-long-sized stackoverflow logo" />
<figcaption>Insanely-long-sized stackoverflow logo</figcaption>
</figure>
</div>
</div>
上面的代码可以很好地显示工具提示,但是有一个小问题。 工具提示不会立即出现在被截断的图像之后,而是出现在隐藏的图像部分结束的位置之后,因此它看起来离图像太远了。
当您向右滚动 .inner-container 时,工具提示会越来越靠近 img,直到它靠近它。
当图像比整个屏幕宽时情况会变得更糟,因为现在工具提示太靠右了,现在它不仅会在.inner-container 中生成预期的滚动条,而且还会在整个页面上生成一个滚动条。
现在无法看到工具提示,因为一旦您尝试滚动工具提示就会消失。
现在的问题是.....
有没有办法配置引导工具提示或使用 css 对其进行样式设置,使其始终出现在裁剪图像的边缘,就像在第二张图像中一样,而不是“实际”但隐藏的边缘?此外,当图像比.inner-container 短时,工具提示应该出现在图像旁边而不是容器的右边缘
【问题讨论】:
标签: css twitter-bootstrap-3 overflow twitter-bootstrap-tooltip