I am trying to output various colors for the tooltips (edit: from Twitter Bootstrap) but it seems I'm not quite getting it. Just changing the default color hasn't been hard, it's just a matter of changing the colors for .tooltip and its associated definitions.
However assuming I wanted to change the color for a specific tooltip within the body
<div id="users" class="row">
<div id="photo_stack" class="span6 photo_stack">
<img id="photo1" src="" width="400px" height="300px" alt="" rel="tooltip" data-placement="right" title="Other Color" />
A simple approach like
#users .tooltip { background-color: #somecolor; }
doesn't seem to work. I guess it's something about the DOM and I'd need to attach some sort of classes to the specific tooltips? Or am I completely off? Thanks :)
Here's a JSFiddle: http://jsfiddle.net/rZxrm/
Twitter bootstrap does not have this feature built in, but you could add your own functions to do this, like so:
and then you just have to define
tooltipPhoto
class in CSS to have a different background color.EDIT: Updated solution:
If you are using tooltip, you might want to use built-in theme colors which are info, success, danger and warning. However Bootstrap does not have support for themes for tooltips (in V3 at the time of writing) but we can add few lines of CSS to achieve this.
Ideally what we want is set of classes
tooltip-info
,tooltip-danger
,tooltip-success
etc that you can apply to element you are invokingtooltip()
. I'll give code below that does exactly this and is tested with Bootstrap 3.0.Result
How does it work
Below code basically reuses styles for alert component as it is very similar to tooltip. Notice that doing so has few advantages including the fact that not only background color is changes but text color as well as border color is changed too. Plus it gives the tooltip slightly transparent glossy look. The arrow in the tooltip depends on border color so that is changed separately by inheriting alert component's border color.
Also note that these are not global changes. Unless you apply classes like
tooltip-info
you get the default tooltip.Usage
Note that Bootstrap tooltips are not activated by default so you need activation like this (see https://stackoverflow.com/a/20877657/207661)
Fiddle
Play with this code here: http://jsbin.com/usIyoGUD/3/edit?html,css,output
LESS CSS Source
Compiled CSS
If you are not using LESS or don't want to deal with it then you can use below compiled CSS directly:
See Dynamically add a class to Bootstrap's 'popover' container
Her fix allows a data-class selector by modifying bootstrap.js with one line
See my reply to a similar question: Change bootstrap tooltip color
It is applicable to style tooltips of the existing and dynamically created elements, using Bootstrap 3 or Bootstrap 4.
Bootstrap 3:
Examples:
for Bootstrap 3
for Bootstrap 4
Here is how I do it in sass
And the position dependent part
I have found another solution for your problem (I was trying to do the same thing). Simply change the color in your main CSS stylesheet (it will override bootstrap's as long as your stylesheet is listed after bootstrap in the head of your doc).
Specifically here's what you add to your main stylesheet (as an example):