New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot customize style of md-tabs #1276
Comments
I see two problems with your Plunk
On this Plunk, I have implemented some of the styles you were going for by putting them in |
I just copy pasted it, I am using scss in my code. But I am able to customize style of md-card for example. I edit the plunk example http://plnkr.co/edit/K1iVNV?p=preview. I notice that my component is generating this css for my style:
But this is being override by this css, where the attribute selector
I really cannot understand this behavior, it seems that md-tabs are a sort of subcomponent...?! |
You need to use /deep/ md-tab-group {
... |
Even using /deep/ .md-checkbox-inner-container{
margin: 4px 0px 0px 0px !important;
} The problem is that I do not want to use !important, so, how can I do this without !important? |
Sometimes I need to put a more specific selector, for example: body <selector> {... instead of <selector> {... If you use SCSS you can use the hierarchy feature to get a better specification of the selectors, and they will win this "competition". |
What do you mean by "the hierarchy feature"? Let's say I have a component that is a table and then I place a |
Let's say we have: <div class="articles">
<article>
<md-checkbox></md-checkbox>
</article>
</div> So you would style in SCSS in this way: .articles{
color: blue; /*style for entire articles section */
article{
color: red; /* style for each article*/
/deep/ md-checkbox .md-checkbox-inner-container{
margin: 4px 0px 0px 0px;
}
}
} It will be translated to: .articles{
color: blue;
}
.articles article{
color: red;
}
.articles article /deep/ md-checkbox .md-checkbox-inner-container{
margin: 4px 0px 0px 0px;
} So |
Thanks @anderflash. Using So we can assume that it is the right behavior because Angular 2 styles (except those that are loaded by index.html) are scoped to the component so one component should not be able to change nested components unless you use |
That's also my view about this issue. I'm also learning it and the tools are evolving rapidly. It still seems like a hack to put /deep/ wherever we want back default css behavior (changing nested components without context). So I think it will change in the future. |
There are three ways to resolve this right now. |
@andrewseguin None of that 3 methods help to customize some styles right now the style of a md-tab header. The only way for now, is to use the !important keyword on the style (and this is not recommended really). |
Perhaps I'm misunderstanding your issue. I am able to change the styling on this tab header by removing view encapsulation and applying styles that have a higher specificity than those defined in the default md CSS. |
No you've not misunderstood it. In your case, as you can see, the encapsulation was not enough, you've added also .my-tabs class. Any case this seems to be a better solution, I would have preferred to have a way just to customize the style without breaking the "rules" |
Yes, it is necessary to use higher specificity in CSS selectors in order to override the default style of the tab header. Does this solution not fit your needs? |
Let says yes but in general I would like to preserve encapsulation of my component and be able to customize the style of my app at the same time. |
I would like to be able to do that as well, but unfortunately this is beyond the bounds of what can be done in material (or any UI toolkit) due to how angular 2 is implemented. Feel free to file an issue with angular to suggest this. |
encapsulation to NONE is the better way to customize tabs component? |
@andrewseguin why you didn't set "md-tab-group" component encapsulated to none ? |
Maybe the same way you can style a toolbar like this:
|
Hello, it works indeed as @ivanntis said. But even if I can change all of the tabs, how can I change only one tab style? I want to add a + at the end in order to add a tab. |
Already mentioned, but I see a few adopting the /deep/ solution. /deep/ is being deprecated, sooner or later your apps will break. |
So what is the best solution? |
@mist3r3 the choices you have are as reported by @andrewseguin earlier in this thread. Since /deep/ is being deprecated the solutions you are left with are (copied from @andrewseguin above): (1) Set view encapsulation to NONE on the component that hosts your tabs and use your component style sheet Personally I use option 1. |
The issue with (1) setting the view encapsulation to NONE is those styles bleed throughout the entire app. If my component's stylesheet I had I would like to say "make this component and all it's children" h1's blue. Setting encapsulation to none I would have to add an application-wide unique selector to my component and use that in the component's stylesheet. But that's what I'm trying to get away from doing and why I fell in love with component view encapsulation. |
@anderflash i did the same thing! and its works! |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug, feature request, or proposal:
Adding custom style to the tabs header
What is the expected behavior?
affect css style of header (font size, color, display....)
What is the current behavior?
Style is beeing totally ignored due to attribute selectors generated by the own element ignoring the styleUrls ones
What are the steps to reproduce?
Create a simple element (html):
Add this style in the .scss:
Plunk demo http://plnkr.co/edit/K1iVNV
What is the use-case or motivation for changing an existing behavior?
Need to customize md tabs style/colors/responsive
Which versions of Angular, Material, OS, browsers are affected?
Angular 2.0, Material alpha 8-2
Is there anything else we should know?
The text was updated successfully, but these errors were encountered: