How to change Popover size in Bootstrap 3?

Asked

Viewed 855 times

1

I have the following code of a Popover effect with Bootstrap 3, I am using Bootstrap 3.3.7. This one can works as follows, when the mouse passes over this icon the message appears. I have several popovers on the page, but that particular one is very great content and I need to increase the width of it so that it does not leave the area of vision. Someone knows how?

Follow my code and image can in operation.

inserir a descrição da imagem aqui

<a href="#" data-toggle="popover" data-placement="left" data-trigger="hover" title="<strong>Informação</strong>" data-content="conteudo vem aqui"><i class="fas fa-question-circle"></i></a>

-

$('[data-toggle="popover"]').popover({html: true});

Libraries that I am using besides the Bootstrap.min.css file downloaded on the site, the version is 3.3.7:

<!-- Font Awesome -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  • Dude are you using any other library that has this Popover? Because it doesn’t look like the default Boostrap model... I put your code there using the standard documentation files I couldn’t simulate that behavior. Include the rest of the information in the question. Extra CSS and JS files you’ve used and more

  • @hugocsl updated the question with all the libraries I’m using

2 answers

0

You can increase not only the width from Popover like any other Css property of it normally:

$(function() {
  $('[data-toggle="popover"]').popover({html: true})
})
.popover-content {
    color: red;
    font-size: 10px;
    width: 300px;             // aumenta o width
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<a href="#" data-teste="popover" data-toggle="popover" data-placement="right" data-trigger="hover" title="<strong>Informação</strong>" data-content="conteudo vem aqui"><i class="fas fa-question-circle"></i></a>

  • 1

    Your method tbm showed me that you can change not only the width, very good!

0


A class .popover of Bootstrap 3 has a max-width default of 270px, just you replace this value in .popover which is followed by the buttom who has a id for example...

#teste + .popover {
    max-width: 350px;
}

I did so, notice that one .popover has a default width of 270px, and the .popover to come after the buttom with id="teste" will have the width I put in the CSS of 350px

$('[data-toggle="popover"]').popover({html: true});
#teste + .popover {
    max-width: 350px;
}
<link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    
<button type="button" id="teste" class="btn btn-lg btn-danger" data-toggle="popover" title="Popover title" data-content="And here's some amazing content. It's very engaging. Right?">345</button>

<br>
<br>
<br>

<button type="button" class="btn btn-lg btn-danger" data-toggle="popover" title="Popover title" data-content="And here's some amazing content. It's very engaging. Right?">123</button>
    

See through Devtools that when you click on buttom is then added a div with class .popover as shown below:

inserir a descrição da imagem aqui

OBS: Here is the official documentation of Bootstrap 3 about the Popover: https://getbootstrap.com/docs/3.3/javascript/#live-demo-1

  • Your answer solved my problem, thank you!

  • @C.Oli cool that worked out! Good luck there with the project!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.