ngx-bootstrap: Style not working on tabs
I have the following setup:
<tabset>
<tab customClass="tab-style">
<template tabHeading>
Tab1
</template>
<div class="tab-page-content">
<!-- content-->
</div>
</tab>
<tab customClass="tab-style">
<template tabHeading>
Tab2
</template>
<div class="tab-page-content">
<!-- content-->
</div>
</tab>
<tabset>
And my styling is:
.tab-style {
background-color: red;
}
// other styling
Now it seems that the customClass “tab-style” is correctly set on the “li” element, but the styling doesn’t seem to work at all.
Picture: http://imgur.com/a/wLk3f
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 20 (2 by maintainers)
this should help: http://valor-software.com/ng2-bootstrap/#/tabs#styling
If you want to overriding bootstrap rule on the component style file, add this on your component
https://github.com/gdi2290/angular-starter/wiki/How-to-include-SCSS-in-components
Hi, @Tommytoe ! If using angular, you need add style.css in .angular-cli.json
and add you class in style.css.
After you was complete this stage you need add you custom class in tabs component.
Result 😃

I had a same issue, but after reading all of above comments, I was able to work around and resolve my issue. Here is what I have and what I see for this specific component.
.tab-style { background-color: red; }, it works since there in no bootstrap rule for it.Workaround:
_nave.scsswhere I override bootstrap-sass, and I put all overriding rules in it.It works! ✨ ps: as a side note: I dont understand why overriding bootstrap rule on the component style file, and style.scss dont answer.
I resolved it like this:
Inside the “.angular-cli.json” under “styles” you have to put “styles.scss” after “bootstrap.css” so it can override the class of bootstrap.
and then you can set the colors of the tabs like this:
This is still an issue, should not have to set ViewEncapsulation to None, that will definitely break some other things.
Its caused by the outputted html not having the _ngcontent attribute for the component
The encapsulation for a component always appends that _ng_content to generated css:
So without the _ngcontent attribute appended to the generated tab elements the CSS won’t match.
@jechazelle Also works for me. Thanks.
It’s extremely inconvenient to be unable to style tabs as easy as the documentation suggests. Why this isn’t considered a bug?
+1 not working… My
customclassis adding in both,<li class="nav-item">and<tab>and it effects in<tab></tab>but not in main<li>.It seems my issue is solved, but I can’t really explain how. I’d read a little more about the CSS encapsulation of Angular2 and decided to test some things. I added
ViewEncapsulation.Noneto my component who’s containing the tabset and it seemed that the styling then worked correctly. But the change broke some other things, so I removed the line again from the component. And to my surprise, the styling kept working. Still my code looks exactly the same as mentioned before.I’m not sure what has been triggered end why the problem is suddenly fixed. At least it doens’t seem to be a problem with your provided component. Thanks for the help anyways and for providing the Angular components.
+1 not working
In my case it’d work if the styling are set in the global styles.css file, but not when they’re set inside the component’s own style file. Could be something related to angular’s css encapsulation.
existing issue: #1410