1

I am using AngularUI Tooltip in a directive as below.

app.directive('customTooltip', function($compile) {
    return {
        link: function(scope, element, attrs) {
        var config = scope.$eval(attrs.appsTooltip);
        var htmlText = '<img src=\'../../../images/help_on.jpg\' tooltip="' + config.message + '" tooltip-placement="' + config.placement + '" />';
        element = element.append(htmlText);
        $compile(element.children())(scope);
    }
};

});

Instead of modifying the actual bootstrap.css class like

.tooltip-inner, .tooltip.top .tooltip-arrow ,etc

How can I use the same directive to overwrite with inline tooltip styling?

1 Answer 1

1

Instead of trying to add in inline styles just add the class to one of your own css files (ie create a bootstrap-override.css) and change the properties you wish to change. You might need to either use !important after the property value to make sure it overrides the others or use a higher specificity

Using !important

.tooltip-inner {
    width:150px !important;
}

Using a higher specificity

.someParentElementClass img.tooltip-inner {
    width:150px;
}

Article on Specificity


You do not need to modify any of the boostrap files. The css classes aren't even in the js file you mention in the comments, that is just setting the class attribute on the element.

All you have to do is create a new css file, put the style you want to override in it in there, and use either the !important flag, or the higher specificity to override the bootstrap styles

bootstrap-override.css

.tooltip-inner {
    width:150px !important;
}

.tooltip.top {
    top:-100px !important;
}

Then in your html include the file after the boostrap files

<head>
   <link rel="stylesheet" href="/boostrap.css" />
   <link rel="stylesheet" href="/boostrap-override.css" />
</head>

This is all you have to do nothing else. And as long as you use the correct specificity or !important the styles will be overriden.

Sign up to request clarification or add additional context in comments.

3 Comments

Do you mean copy and paste bootstrap.css into bootstrap-override.css and modify the properties? I thought there is a better way
No do not copy paste from the boostrap css file just make a new css file and put in that the classes you wish to override
If i do that then i would need to use !important inside ui-bootstrap-tpls-0.10.0.js since that's where the css class is defined but i do not want to modify ui-bootstrap-tpls-0.10.0.js

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.