Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the width of twitter bootstrap popover

I am trying to change the width of twitter bootstrap popover using bootstrap 3:

<button type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="right" data-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus.">
$('#popover').popover(options)

At the moment the content in the popover spreads over two lines. I want the popover content to stay on one line. Is this possible?

I am using C#, html and css.

like image 500
user3395822 Avatar asked Mar 08 '14 10:03

user3395822


People also ask

How do you increase the width of a Popover in material UI?

The easiest way of doing that is to stretch the content inside the Popover, because it's width is calculated automatically. And that will stretch Popover itself to desired size.

What is ngbPopover?

ngbPopover. The string content or a TemplateRef for the content to be displayed in the popover. If the title and the content are falsy, the popover won't open. Type: string | TemplateRef<any>| null | undefined. openDelay.


2 Answers

You can change the popover's dimensions with CSS:

.popover{
    width:200px;
    height:250px;    
}

But that CSS will change ALL popovers. What you need to do is put the button in a container element and use CSS like this:

#containerElem .popover {
  width:200px;
  height:250px;
  max-width:none; // Required for popovers wider than 276px (Bootstrap's max-width for popovers)
}

You also need to change data-container="#containerElem" to match your container.

NOTE: If your popover is going to have a width greater than 276px, you need to override the max-width property as well. So add max-width: none to the .popover {} class.

Here's a jsFiddle: http://jsfiddle.net/4FMmA/

like image 153
Gavin Avatar answered Oct 18 '22 03:10

Gavin


If you want to controle the width in javascript:

HTML (example from Bootstrap)

<button id="exampleButton" type="button" class="btn btn-default" data-container="body" data-toggle="popover" data-placement="top" data-content="Vivamus sagittis lacus vel augue laoreet rutrum faucibus.">
  Popover on top</button>

Javascript:

We set the max-width when show.bs.popover event is triggered:

var p = $("#exampleButton").popover();
p.on("show.bs.popover", function(e){
    p.data("bs.popover").tip().css({"max-width": "500px"});
});

http://jsfiddle.net/ctoesca/u3kSk


  • You can also add a data-max-width attribute on the button element and get the value in the trigger function:

p.on("show.bs.popover", function(e){
    var w = $(this).attr("data-max-width");
    p.data("bs.popover").tip().css({"max-width": w});
});
like image 17
c-toesca Avatar answered Oct 18 '22 01:10

c-toesca