I use Bootstrap v.3.3.7 and have one dynamic content editor. All options for that editor are stored inside the 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. It goes out from top side of the window to popover be bottom or if go totally bottom to show position top.
To create a popover, you need to add the data-bs-toggle="popover" attribute to an element. Whereas, popover's title and its content that would display upon trigger or activation can be specified using the title and data-bs-content attribute respectively. Here is the standard markup for adding a popover to a button.
So to move the popover more to the left, we can add a negative margin-left, or a positive one to move it further to the right. Likewise, we can move the popover more up by adding a negative margin-top, and down by using a positive value.
In Bootstrap 4, you can position the tooltip in various directions (left, right, top, bottom). The positioning of the tooltip is set by using the third-party library (Popper. js) before bootstrap. js in order for the tooltip to work.
You can use data-placement="auto"
When
"auto"
is specified, it will dynamically reorient the popover.For example, if placement is
"auto left"
, the popover will display to the left when possible, otherwise it will display right.
$(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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With