Changing the width of Bootstrap popover

后端 未结 23 1413
北恋
北恋 2020-11-27 10:51

I am designing a page using Bootstrap 3. I am trying to use a popover with placement: right on an input element. The new Bootstrap ensures that if you use

相关标签:
23条回答
  • 2020-11-27 11:13

    For people who prefer the JavaScript solution. In Bootstrap 4 tip() became getTipElement() and it returns a no jQuery object. So in order to change the width of the popover in Bootstrap 4 you can use:

    }).on("show.bs.popover", function() {
        $($(this).data("bs.popover").getTipElement()).css("max-width", "405px");
    });
    
    0 讨论(0)
  • 2020-11-27 11:13

    You can use attribute data-container="body" within popover

    <i class="fa fa-info-circle" data-container="body" data-toggle="popover"
       data-placement="right" data-trigger="hover" title="Title"
       data-content="Your content"></i>
    
    0 讨论(0)
  • 2020-11-27 11:14

    I had the same problem. Spent quite some time searching for an answer and found my own solution: Add following text to the head:

    <style type="text/css">
        .popover{
            max-width:600px;
        }
    </style>
    
    0 讨论(0)
  • 2020-11-27 11:15

    To change the popover width you may override the template:

    $('#name').popover({
        template: '<div class="popover" role="tooltip" style="width: 500px;"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"><div class="data-content"></div></div></div>'
    })
    
    0 讨论(0)
  • 2020-11-27 11:15

    In bootstrap 4 you can simply override default value of bootstrap variable $popover-max-width in your styles.scss file like so:

    $popover-max-width: 300px;
    
    @import "node_modules/bootstrap/scss/functions";
    @import "node_modules/bootstrap/scss/variables";
    @import "node_modules/bootstrap/scss/mixins";
    @import "node_modules/bootstrap/scss/popover";
    
    

    More on overriding bootstrap 4 defaults https://getbootstrap.com/docs/4.0/getting-started/theming/#variable-defaults

    0 讨论(0)
  • 2020-11-27 11:17

    Here's the non-coffeescript way of doing it with hover:

    $(".product-search-trigger").popover({
        trigger: "hover",
        container: "body",
        html: true,
        placement: "left"
      }).on("show.bs.popover", function() {
        return $(this).data("bs.popover").tip().css({
          maxWidth: "300px"
        });
      });
    });
    
    0 讨论(0)
提交回复
热议问题