Material: Centered tabs

Created on 21 Mar 2015  Â·  28Comments  Â·  Source: angular/material

Is there a way to center tabs like in G+?

capture d ecran 2015-03-21 10 06 47

Most helpful comment

md-center-tabs="true" did the trick just like that FYI

All 28 comments

On line 48 of https://github.com/angular/material/blob/master/src/components/tabs/tabs.scss,
it looks like center is an (ng-)attribute of md-tabs.

I have no time to try it right now, but I would like if you give me some feedback if you test it, thank you.

I think you can "only" stretch them, see the doc.

So maybe you can place them into another fixed-width container that is centered (think flexbox), so the tabs do not stretch on all the topnav's width, like in the example you are showing.

OK I think I have it. See this codepen and please let me know.

It works well. Thank you, @bonatoc for taking the time.

I adapted your code a little for small sized screen: codepen.

Should we keep this issue open and tagged as improvement?

I'm not sure.

We could contribute by making a md-centered-tabs attribute following the "wrapped-inside-centered-container" method in the codepen above and request a pull.

But I think the md-stretch-tabs attribute already does the job.
Frameworks are there to be hacked, worked with.
We can't expect them to have all the options, and I don't think it is the way to go. You end up overbloating it (see Bootstrap...).

Maybe you could tagged the issue as improvement for the demos ?

Many devs would like the centered tabs option displayed as an example.

Can we fork the docs a make a pull request on the demos?

I tried to write a simple md-centered-tabs directive, but it is not simple. I gave up.

Your solution, @bonatoc, should be kept somewhere. She's very useful.

Support for centered tabs is on my list, and I will be hopefully getting to this today.

Awesome @robertmesserle. And again, thanks @bonatoc.

Awesome @robertmesserle

@remicastaing , you're welcome. I was on the same issue myself.

both codepens don't work for me

so can i use centered tabs?

@super-coder — if you're super, please provide more info: version, specific problem?

image

image

md-center-tabs="true" did the trick just like that FYI

i submitted an issue https://github.com/angular/material/issues/7695, tabs are hidden after reload on IE on XS screen

@super-coder — Please provide IE version.

@bonatoc what do you mean? you don't understand how code doesn't work in IE?? There is no IE version

"There is no IE version" - I beg your pardon?

@bonatoc you can see the screen in https://github.com/angular/material/issues/7695

Like tagged: "need more info".

added more info there

just for you to know this works wonders as well





here's the working code
<md-center-tabs> <md-tabs md-cnter-tabs="true" md-dynamic-height md-border-bottom> <md-tab label="Policy Dashboard"> <md-content class="md-padding"> <h1 class="md-display-2">Policy Dashboard</h1> <p>{{lorem}}</p> </md-content> </md-tab> <md-tab label="What is this policy?"> <md-content class="md-padding"> <h1 class="md-display-2">What is this policy?</h1> <p>{{lorem}}</p> </md-content> </md-tab> <md-tab label="Who uses this Policy?"> <md-content class="md-padding"> <h1 class="md-display-2">Who uses this Policy?</h1> <p>{{lorem}}</p> </md-content> </md-tab> </md-tabs> </md-center-tabs>

replace ({lorem}} by the content of your choice of course

Just add md-center-tabs="true" in md-tabs is OK, jonathanmeguira's code doesn't work because he spell mistake 'center'.

my bad @TXZdream

open angular.material.js and search for: material.components.tabs
there you will find everything about the tabs and how they work.

Source Code

build*

EXAMPLE:
<md-tabs mdTabScroll md-align-tabs="top" md-selected="0" md-dynamic-height md-border-bottom layout-fill md-stretch-tabs="always" md-center-tabs md-swipe-content>

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LeoLozes picture LeoLozes  Â·  3Comments

nikhildev picture nikhildev  Â·  3Comments

bobber205 picture bobber205  Â·  3Comments

PeerInfinity picture PeerInfinity  Â·  3Comments

WebTechnolog picture WebTechnolog  Â·  3Comments