温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Bootstrap弹出框(Popover)被挤压的问题小结

发布时间:2020-08-19 21:05:36 来源:脚本之家 阅读:162 作者:低级写手 栏目:web开发

比较了下Bootstrap的popover和一些其它的开源项目,觉得Bootstrap的还算不错。没想到第一次就遇到了一个问题。

弹出框显示的时候如果贴近一个列的边沿,就会很窄,如果一个列比较宽还好,而如果遇到这样的列比如:<div class="col-md-2">,几乎任意位置显示的弹出框都被挤压了。

先看看我的实现以及效果:

js:

$(function (){
 $("[data-toggle='popover']").popover({
  trigger: 'hover'
 });
});

html:

<div class="col-md-1">
 ...
 <img src="..." width="50" height="50" data-toggle="popover" data-content='...' title="..." />
 ...
</div>

效果

Bootstrap弹出框(Popover)被挤压的问题小结

不过解决起来很简单,只需在初始化的时候添加一个container属性就可以了:

$(function (){
 $("[data-toggle='popover']").popover({
  trigger: 'hover',
 container: 'body'
 });
});

我们把容器设置成整个页面的body,这样popover就有足够宽的地方了。

Bootstrap弹出框(Popover)被挤压的问题小结

实际上在官网上对container的作用是有说明的地址  ,只是没有注意到:

Appends the popover to a specific element. Example: container: 'body'. This option is particularly useful in that it allows you to position the popover in the flow of the document near the triggering element - which will prevent the popover from floating away from the triggering element during a window resize.

以上所述是小编给大家介绍的Bootstrap弹出框(Popover)被挤压的问题小结,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对亿速云网站的支持!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI