Custom Data Placement for Bootstrap Popovers

I recently needed to define a unique position for only certain bootstrap popovers.

If you don’t have multiple popovers on the same page, this is easy accomplished through CSS:

.popover.bottom {
  margin-top: 30px;
}
.popover {
  left: 100px !important;
}

However, this will effect all popovers on the page. I needed this to only be applied to popovers that resided in our sidebar. To pull this off, the trick was to update the popover’s template.

By default, Bootstrap defines the popover template as so:

<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>

Here we can add a unique css class to the popover:

<div class="popover popover-sidebar" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>

And place this new template into the popover’s “template” data attribute when enabling:

$('.sidebar_popover_link').popover({
    html : true,
    template: '<div class="popover sidebar" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
});

Update your popover links to reference the new popover js:

<a data-container="body" data-toggle="popover" data-placement="bottom" class="sidebar_popover_link">

Finally, update the CSS to only be applied to these popovers:

.popover-sidebar.bottom {
  margin-top: 30px;
}
.popover-sidebar {
  left: 100px !important;
}</a>
 
146
Kudos
 
146
Kudos

Now read this

Using Laravel with Travis CI for Automated Testing

As I mentioned in our post about Growing Pains, it’s time for us to start building some serious automated testing into Tend. What I needed was a simple way to not only create tests, but to also run them automatically whenever changes are... Continue →