Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap popover clipped to extent of containing div

I want a popover to be contained within a collapsible div: http://jsfiddle.net/nathan9/qgyS7/. However, the popover seems to be limited to the extent of the div. Is there a way to prevent the clipping?

<a href="#toggle" data-toggle="collapse" data-target="#toggle" onClick="return false;">Toggle collapse</a>
<div id="toggle" class="collapse" style="background-color: yellow">
    Content of collapsible div. Click for popover: 
    <i class="icon-info-sign" id="info"></i>
</div>

...

<script>
    $('#info').popover({ html: true, placement: 'left', title: 'Popover', content: "<ul><li>The</li><li>popover</li><li>is</li><li>clipped.</li></ul>" });
</script>
like image 227
nathan9 Avatar asked Nov 07 '12 00:11

nathan9


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.

How do I enable popovers in bootstrap?

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.

How do I show popover on hover?

To make the image on hover in popover just insert an image as an HTML element to the data-mdb-content and set the data-mdb-html to true .


2 Answers

Using timer is always a risky business. I've used a variant of Mike Lucid that listens to the collapsible event, shown and hide.

Here is a working fiddle

The code is as follow:

$(document).ready(function(){
  $('#toggle')
    .on('shown', function(evnt) {
      $(evnt.target).addClass('visible');  
    })
    .on('hide', function(evnt) {
      $(evnt.target).removeClass('visible');  
    })
  ;   
});

If you want your collapsable to be visible on load, don't forget to add classes in and visible to your collapsable div.

Edit

Starting with Bootstrap 2.3, tooltips and popover have a new container option. If you set the container to 'body', your tooltips and popovers will won't be clipped. Here is a working fiddle.

Hope that helps.

like image 98
Renault Avatar answered Oct 04 '22 20:10

Renault


adding .collapse.in {overflow:visible} seems to do the trick

http://jsfiddle.net/ZArX7/

EDIT: Above answer only worked in chrome

Here is a piece of jquery that delays adding the class.

     $('#toggle_link').click(function() {
    if($('#toggle').hasClass('in')){
        $('#toggle').removeClass('visible');
    }else{
        setTimeout(function() {
            $('#toggle').addClass('visible');
        }, 1000);
    }
});   

This solution works

http://jsfiddle.net/fnP7y/

like image 45
Mike Lucid Avatar answered Oct 04 '22 19:10

Mike Lucid