Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am using bootstrap UI with angular directives. And I want to change the default styles bootstrap applies for its elements. Should I target the HTML contents from the template? For example from here, I use accordion. When I define it in HTML, it has the following structure:

<accordion>
    <accordion-group heading="my heading">
      content here
    </accordion-group>

But when the directive processes the template it turns it into the following HTML:

<accordion close-others="oneAtATime"><div class="panel-group" ng-transclude="">
    <div class="panel panel-default ng-isolate-scope" heading="my heading">
        <div class="panel-heading">
            <h4 class="panel-title">
                <a class="accordion-toggle" ng-click="toggleOpen()" accordion-transclude="heading">
                    <span ng-class="{'text-muted': isDisabled}" class="ng-binding">content here</span>
                </a>
            </h4>
        </div>
        <div class="panel-collapse collapse" collapse="!isOpen" style="height: 0px;">
        <div class="panel-body" ng-transclude=""><span class="ng-scope">some content here</span></div>
    </div>

As you can see, it changes it quite significantly. So if I wanted to change how panel title is displayed, should I write in my css files

div.panel {}

and hope that the template doesn't change in the future?

What is the general approach to changing styles for HTML elements generated by directive's templates?

share|improve this question
    
I don't quite have time to supply a proper, thought-out answer. But here's a Plunker I made in case anyone finds it useful: plnkr.co/edit/Bs9hCqCDkSmO4OtR716A?p=preview –  stellarchariot Jul 16 at 6:31

1 Answer 1

If you include your css (site-specific.css) after Bootstrap's (bootstrap.css), you can override rules by redefining them.

For example, if this is how you include CSS in your <head>

<link rel="stylesheet" href="css/bootstrap.css" />
<link rel="stylesheet" href="css/site-specific.css" />

You can simply override the panel (in your site-specific.css file):

.panel {
    //your code here
}

And do not bother template change in the future. As you use a specific version, updates will not effect you. They are generating a new template with a new version name.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.