I am trying to create a page with images in popovers I used a demo online to create it but when the image gets larger than a certain size it begins to overflow out of the popover. How do I fix this?
Js Fiddle here: https://jsfiddle.net/rdvL6kj9/10/
html:
<div class="container my-4">
<p class="font-weight-bold">This simple example shows how to place an image within a bootstrap popover. You can
define if you want to launch the popover on hover or on click.</p>
<p><strong>Detailed documentation and more examples of Bootstrap grid you can find in our <a href="https://mdbootstrap.com/docs/jquery/javascript/popovers/"
target="_blank">Bootstrap Popovers Docs</a></strong></p>
<a class="btn btn-primary" data-toggle="popover-hover" data-img="https://placekitten.com/500/300">Hover
over me</a>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
js:
// popovers initialization - on hover
$('[data-toggle="popover-hover"]').popover({
html: true,
trigger: 'hover',
placement: 'bottom',
content: function () { return '<img src="' + $(this).data('img') + '" />'; }
});
You were almost there. I have added a bootstrap in-built class > class="img-fluid"
to the img
tag to make it responsive across all the images
$('[data-toggle="popover-hover"]').popover({
html: true,
trigger: 'hover',
placement: 'bottom',
content: function () { return '<img src="' + $(this).data('img') + '" class="img-fluid"/>'; }
});
Here is the working fiddle