14

Does anybody please know how to center-align the tabs in jQuery UI tabs?

(They are left aligned by default and I can't find the aligning option in the doc)

Here is a page where I use it to groups some charts and the current code is simply:

$('#chart_tabs').tabs();

enter image description here

UPDATE: The CSS code:

.ui-tabs .ui-tabs-nav {
        text-align: center;
}

.ui-tabs .ui-tabs-nav li {
        float: none !important;
        display: inline-block;
}

suggested by Didier (thanks) has center-aligned the tabs, but also put some strange gap underneath the tab-"buttons":

enter image description here

Martin Brisiak
  • 3,872
  • 12
  • 37
  • 51
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416

5 Answers5

12

This snipped help me out back in the days..

.centered .ui-tabs-nav {
    height: 2.35em;
    text-align: center;
}
.centered .ui-tabs-nav li {
    display: inline-block;
    float: none;
    margin: 0em;
}

maybe this works for you too

pabera
  • 1,042
  • 1
  • 13
  • 22
12

The easiest way is to apply text-align: center on the container (the UL element) and unfloat the LI:

.ui-tabs .ui-tabs-nav {
    text-align: center;
}

.ui-tabs .ui-tabs-nav li {
    float: none !important;
    display: inline-block;
}
Didier Ghys
  • 30,396
  • 9
  • 75
  • 81
2

This worked for me and avoided the gap (underneath the tabs) you mentioned:

.ui-tabs-nav {
  float: none; text-align: center;  
}

.ui-tabs-nav li {
  display: inline-block; float: none;  
}

.ui-tabs-nav li a {
  float: none;
} 
Mayinx
  • 304
  • 1
  • 6
  • 9
1
.ui-tabs .ui-tabs-nav {
  text-align: center;
}

.ui-tabs .ui-tabs-nav li {
  float: none !important;
  display: inline-block;
}

.ui-tabs .ui-tabs-nav li.ui-tabs-active {
  margin-bottom: -8px;
}

.ui-tabs .ui-tabs-nav li {
  margin: 1px .2em -7px 0;
}
Paulo
  • 11
  • 1
0

another nice approach in modern days:

.ui-tabs .ui-tabs-nav {
    display: flex;
    justify-content: center;
}