components icon indicating copy to clipboard operation
components copied to clipboard

Cannot customize style of md-tabs

Open albanx opened this issue 10 years ago • 27 comments

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):

<md-tab-group>
    <md-tab>
        <template md-tab-label>Personal info</template>
        <template md-tab-content>
            <h4>Name, address</h4>
            <div class="">
                Some data here
            </div>
        </template>
    </md-tab>

    <md-tab>
        <template md-tab-label>Payment</template>
        <template md-tab-content>

            <div class="">
                Payment setup
            </div>
        </template>
    </md-tab>
</md-tab-group>

Add this style in the .scss:

md-tab-group {
    .md-tab-header {
        font-size: 12px !important;
        display: flex;
        flex-flow: row wrap;
        align-items: center;
        .md-tab-label {
            flex: 1;
            min-width: 1px;
        }
    }
}

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?

albanx avatar Sep 19 '16 21:09 albanx

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. Thank you.

mist3r3 avatar May 22 '17 12:05 mist3r3

Already mentioned, but I see a few adopting the /deep/ solution. /deep/ is being deprecated, sooner or later your apps will break.

ksiabani avatar Jul 18 '17 12:07 ksiabani

So what is the best solution?

mist3r3 avatar Jul 19 '17 06:07 mist3r3

@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 (2) Load a separate style sheet apart from Angular (e.g. through index.html) that affects the tabs

Personally I use option 1.

ksiabani avatar Jul 27 '17 14:07 ksiabani

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 h1 { color: blue } then when changing the component from Emulated to None it makes ALL h1 elements blue that don't have a color defined by a more specific rule.

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.

jraadt avatar Jul 30 '17 01:07 jraadt

@anderflash i did the same thing! i wrapped it into a css class e.g --> class ="test" --> test{ /deep/ md-checkbox .md-checkbox-inner-container{ margin:..; } }

and its works!

AnthonyNahas avatar Aug 03 '17 20:08 AnthonyNahas

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.