简体   繁体   English

更改内容位置上引导程序弹出窗口的顶部或底部位置

[英]Change top or bottom position of bootstrap popover on content position

I use Bootstrap v.3.3.7 and have one dynamic content editor. 我使用Bootstrap v.3.3.7并拥有一个动态内容编辑器。 All options for that editor are stored inside the popover. 该编辑器的所有选项都存储在popover中。

I have a problem when some of the content is at the bottom or top because of popover push content and whole page. 我有一个问题,当一些内容位于底部或顶部时,因为弹出式推送内容和整个页面。 Here are examples: 以下是示例:

在此输入图像描述

在此输入图像描述

I generally want, if popover goes out of margins to automatically change position. 我通常想要,如果popover超出边距以自动改变位置。 It goes out from top side of the window to popover be bottom or if go totally bottom to show position top. 它从窗口的顶部向外突出到底部或者如果完全在底部显示位置顶部。

You can use data-placement="auto" 你可以使用data-placement="auto"

When "auto" is specified, it will dynamically reorient the popover. 指定"auto" ,它将动态重定向弹出窗口。

For example, if placement is "auto left" , the popover will display to the left when possible, otherwise it will display right. 例如,如果展示位置为"auto left" ,则弹出窗口将尽可能显示在左侧,否则它将显示为右侧。

 $(function() { $('[data-toggle="popover"]').popover() }) 
 .flex { display: flex; height: 50vh; justify-content: space-between; align-items: flex-start; } 
 <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.7/js/bootstrap.min.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" /> <div class="flex"> <button type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="auto" data-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus."> Popover Auto position </button> <button type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="auto" data-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus."> Popover Auto position </button> </div> <div class="flex" style="align-items: flex-end;"> <button type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="auto" data-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus."> Popover Auto position </button> <button type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="auto" data-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus."> Popover Auto position </button> </div> 

making position absolute will do the trick for you . 绝对的位置将为你做到这一点。 however you can try it in the different way . 但是你可以用不同的方式尝试。 here is the example of how you can do it 这是你如何做到这一点的例子

https://getbootstrap.com/docs/3.3/javascript/ https://getbootstrap.com/docs/3.3/javascript/

This might not be helpful to you, but you could always use float:right; 这可能对你没有帮助,但你总是可以使用float:right; and then do some padding or margins. 然后做一些填充或边距。 Again, this might not be very helpful, but I'm pointing it out in case it is. 同样,这可能不是很有帮助,但我指出它以防万一。

PS As said above, you can also use data-placement="auto" PS如上所述,你也可以使用data-placement =“auto”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM