Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to position a Bootstrap popover?

I'm trying to position a Bootstrap popover for a trigger that sits on the far top-right corner of a 960px wide web page.

Ideally, I'd position it on the bottom and move the arrow with CSS (so the arrow is on the top-right of the popover). Unfortunately the 'placement':'bottom' positioning is not enough, since it will center it below the trigger.

I'm looking for solution that will place the popover statically below and on the left of the trigger.

like image 563
koichirose Avatar asked May 29 '12 11:05

koichirose


People also ask

How do I change the popover position in bootstrap?

Positioning with Margins 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 you move Popovers?

At the moment, the only way to move the mouse to the popover is by follwing the small arrow underneath the popover.

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 use bootstrap Popovers?

To create a popover, add the data-toggle="popover" attribute to an element. Note: Popovers must be initialized with jQuery: select the specified element and call the popover() method.


2 Answers

This works. Tested.

.popover {     top: 71px !important;     left: 379px !important; } 
like image 101
rboarman Avatar answered Oct 12 '22 05:10

rboarman


Simply add an attribute to your popover! See my JSFiddle if you're in a hurry.

We want to add an ID or a class to a particular popover so that we may customize it the way we want via CSS.

Please note that we don't want to customize all popovers! This is terrible idea.

Here is a simple example - display the popover like this:

enter image description here

// We add the id 'my-popover'  $("#my-button").popover({      html : true,      placement: 'bottom'  }).data('bs.popover').tip().attr('id', 'my-popover');
#my-popover {      left: -169px!important;  }  #my-popover .arrow {      left: 90%  }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>  <link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>  <script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>    <button id="my-button" data-toggle="popover">My Button</button>
like image 23
Mick Avatar answered Oct 12 '22 05:10

Mick