Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change top or bottom position of bootstrap popover on content position

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:

enter image description here

enter image description here

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.

like image 862
Ivijan Stefan Stipić Avatar asked Aug 24 '17 15:08

Ivijan Stefan Stipić


People also ask

How do I customize bootstrap popover?

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.

How do you move a popover to the left?

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.

How do I change the position of the tooltip in bootstrap?

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.


2 Answers

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>
like image 107
Abhishek Pandey Avatar answered Oct 05 '22 23:10

Abhishek Pandey


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/

like image 34
Mitesh Avatar answered Oct 06 '22 00:10

Mitesh