css - Bootstrap popover - 将其移动到左侧/右侧

标签 css twitter-bootstrap popover

我想在左侧重新定位我的 bootstrap popover,即我想将整个 popover 移动到左侧,而白色箭头将留在一个位置。

我想要 google.com 网站上的效果,当您单击蓝色图标时,您会看到弹出窗口,但其内容已重新定位,而白色箭头位于用户下方。

我知道我可以使用这样的东西:

.popover {
    top:0 !important;
    margin-top:10px;
}

不幸的是,它用白色箭头重新定位了整个弹出窗口。

我现在拥有的(弹出窗口在右侧,屏幕边缘和我的弹出窗口之间没有空间)

enter image description here

我想要的(弹出窗口和显示器边缘之间的小距离):

enter image description here

最佳答案

“I want to change the position of content of this popover so that this arrow will be placed further on the left„

当显示弹出窗口时,箭头位置是根据宽度/高度和位置在 Tooltip.prototype.replaceArrow 中计算的。您可以使用此 CSS 强制指定位置:

.popover .arrow {
    left: 90px !important; /* or 45% etc */
}

但这会影响所有的弹出窗口。 Popovers 被注入(inject) DOM 或从 DOM 中移除,默认情况下无法单独定位可见的 popovers。如果您想在特定弹出窗口上设置箭头样式,解决方法是挂接到 shown.bs.popover 事件,检测正在显示的弹出窗口,并在需要时为该弹出窗口设置箭头样式.示例:

.on('shown.bs.popover', function() {    
    var $popover = $('.popover')[0];
    switch ($(this).attr('id')) {
        case 'a' : $popover.find('.arrow').css('left', '10px');break;
        case 'b' : $popover.find('.arrow').css('left', '40%');break;            
        case 'c' : $popover.find('.arrow').css('left', '180px');break;            
        default : break;            
    }   
})

要让它工作,必须一次只显示一个弹出窗口(参见 fiddle )。它也可以用多个可见的弹出框来解决,但是我们需要向弹出框内容添加一些 HTML。

查看演示 -> http://jsfiddle.net/uteatyyz/

关于css - Bootstrap popover - 将其移动到左侧/右侧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25117723/

相关文章:

html - IE7 中的 CSS 问题

css - 使用 Angular js 在页面刷新时随机更改 div 背景图像

css - 更改 CSS "bold"属性字体粗细值

html - 无法在 Bootstrap 导航中垂直居中非 anchor 标签

iOS 获取一个 UITableViewCellAccessoryDe​​tail 的 View

javascript - JQuery-Bootstrap-Expanding-Vertical-Menu 重叠 Bootstrap 网格系统

html - 仅使用 CSS 使第一列在 react 表中变粘

jquery - 制作堆叠的响应 block ,在调整大小时改变高度和宽度

javascript - 弹出窗口中的溢出滚动条不起作用( Bootstrap )

ios - 自定义 UIPopoverController View 背景和边框颜色