-1

I want to give a background colour to the pointing element of a popover. How can I do so? jsfiddle for the code

.popover{
   background:rgba(128, 21, 21,0.8);
   font-weight: bold;
   border-radius: 2%;
}
.popover-body{
   background:rgba(128, 21, 21,0.8);
   color: #ffffff;
}

enter image description here

Achal Gupta
  • 424
  • 4
  • 15

3 Answers3

3

Custom color popover

After taking a look at bootstrap v4.1.3 css file:

The css your searching for is .popover .arrow::after css rule.
But changing this will change all popovers on your site.
So we want to choose the ones we select with a custom class. .custom in the example.

Example:

$(function() {
  let e = $('[data-toggle="popover"]').popover().data('bs.popover').getTipElement();
  console.log(e);
  $(e).addClass("custom");
});
.popover {}

.custom .popover-body {
  background-color: red;
}

.custom .popover-header {
  background-color: darkred;
}

.custom .arrow {}

.custom.popover .arrow::after {
  border-right-color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>


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

So the explanation is:

  • Use javascript to add a class to the popover (class is "custom" in exaple above)
  • Add your own css rules with higher specificity.
  • Remember to the correct styles. (its a css triangle)
Persijn
  • 14,624
  • 3
  • 43
  • 72
  • Thanks a lot. It worked. Example of css triangle helped me in understanding the problem. – Achal Gupta Aug 22 '18 at 12:37
  • @AchalGupta yeah i was considering linking it. I'll do it here for others to find: https://stackoverflow.com/questions/7073484/how-do-css-triangles-work – Persijn Aug 22 '18 at 13:05
0

If it's bootstrap tooltip pls try code i written below

.tooltip.top .tooltip-arrow {
    border-top-color: #870a17; /* or what ever color you want*/
}

but it will work only if it's bootstrap tooltip with top option if anything else you should have to give code.

0

If it is bootstrap then please search in CSS. There must be present class like .bs-popover-top .arrow::before.

Make changes in it or you can write your own similarly like below.[note : you can change class name as per your code]

.bs-popover-top .arrow::before{ border-top-color:#f00; }

Ambuj Khanna
  • 1,131
  • 3
  • 12
  • 32