Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styling a tooltip (popper.js / bootstrap v4 beta)

I've installed bootstrap v4 beta and with it the popper.js (tooltip.js) library. I'm trying to use it's tooltip function. So I managed to make it appear but I can't change it's appearance/style for the life of me. I've looked over their documentation several times but I can't figure it out. (I just hate a so called "documentation" that doesn't have examples). So here is my html:

<span data-toggle="tooltip" data-placement="right" title="Tooltip on right">Simple Task Management</span>

I activated it on data-toggle in js:

$(function() {
    $('[data-toggle="tooltip"]').tooltip()
})

I noticed that when the tooltip appears a new div is created with the class "tooltip ..." so I thought I could target that class and style it in my scss, so:

.tooltip {
    background-color: #DB2828;
    color: $green;  
}

Not my intended styling options, just tested to see it work...well the result: enter image description here

The same black background with my test background behind it...can someone help me figure this out? Many thanks.

like image 576
Alin Faur Avatar asked Aug 30 '17 08:08

Alin Faur


People also ask

How do I add a tooltip in Bootstrap 4?

Bootstrap 4 - Tooltips. Description. Tooltips are useful when you need to describe a link. Tooltip will display a small pop-up box, when you hover the mouse on an element. Creating a Tooltip. You can add tooltip to an element by adding data-toggle = "tooltip" attribute to it. The title attribute indicates the text of a tooltip.

Do I need to include Popper before or after bootstrap?

You must include popper.min.js before bootstrap.js in order for tooltips to work! Tooltips are opt-in for performance reasons, so you must initialize them yourself.

How do I add a tooltip to a popper page?

Create a new HTML document with two elements, a <button> and a tooltip <div>, and pass them to Popper: Let's give our tooltip some styling: Here's the result so far: Our tooltip is currently just a box. In many UI design systems, this is all tooltips need, but others prefer to have an arrow that points toward the reference element.

How to display a pop-up box with a tooltip?

Tooltip will display a small pop-up box, when you hover the mouse on an element. You can add tooltip to an element by adding data-toggle = "tooltip" attribute to it. The title attribute indicates the text of a tooltip.


2 Answers

The structure of the tooltip is described in the docs. To change the style you need to override tooltip-inner and arrow:

Update for Bootstrap 4.0.0

Demo

.tooltip-inner {
    background-color: #00cc00;
}
.tooltip.bs-tooltip-right .arrow:before {
    border-right-color: #00cc00 !important;
}
.tooltip.bs-tooltip-left .arrow:before {
    border-left-color: #00cc00 !important;
}
.tooltip.bs-tooltip-bottom .arrow:before {
    border-bottom-color: #00cc00 !important;
}
.tooltip.bs-tooltip-top .arrow:before {
    border-top-color: #00cc00 !important;
}

(where #00cc00 is the desired tooltip color)

like image 174
Zim Avatar answered Oct 21 '22 13:10

Zim


For me I had to do this instead for the bottom tooltip :

.tooltip-inner {
  background-color: $darkGrayClr;
}
.tooltip.bs-tooltip-bottom .arrow:before {
  border-bottom-color: $darkGrayClr;
}
like image 45
Symro Avatar answered Oct 21 '22 15:10

Symro