chubbyk
chubbyk

Reputation: 6302

How to align tabs to top/right in bootstrap 3?

I need to align bootstrap 3 tabs to right instead of left.

Is it possible with usage of bootstrap css or do I need to use custom css ?

Upvotes: 31

Views: 62433

Answers (10)

Andy
Andy

Reputation: 3012

In case someone here is looking for an answer using bootstrap 4:

You can add ml-auto to the tab you want to push to the right

<ul class="nav nav-tabs small" role="tablist">
    <li class="nav-item">
        <a class="nav-link active" data-toggle="tab" href="#first" role="tab">First</a>
    </li>
    <!-- .ml-auto: adds margin to the left of this tab, all tabs behind this one, are pushed to the right -->
    <li class="nav-item ml-auto"> 
        <a class="nav-link" data-toggle="tab" href="#second" role="tab">Second</a>
    </li>
    <li class="nav-item">
        <a class="nav-link" data-toggle="tab" href="#third" role="tab">Third</a>
    </li>
</ul>

bootstrap docs: auto-margins

Upvotes: 7

eladcm
eladcm

Reputation: 582

I know it's an old post, how ever the soultion is simple :

CSS

.nav-rtl {
    padding-left:40px;
    padding-right:0px;
}

.nav-rtl li {
    float:right;
}

HTML

<ul class="nav nav-tabs nav-rtl" role="tablist">
    <li ..... ></li>
    <li ..... ></li>  // an so on
</ul>

Upvotes: 15

Roland
Roland

Reputation: 736

A very simple and good solution is described already here by balexandre:

Align a bootstrap navbar to the right

.right-to-left li {
  float: right !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>


<h2>Bootstrap tab aligned right</h2>
<ul class="nav nav-tabs right-to-left">
  <li role="3" class="active"><a href="#">Tab 3</a></li>
  <li role="2"><a href="#">Tab 2</a></li>
  <li role="1"><a href="#">Tab 1</a></li>
</ul>

(not that the tabs are ordered reverse)

Upvotes: 1

VK321
VK321

Reputation: 5953

Add class justify-content-end

<ul class="nav nav-tabs justify-content-end" role="tablist">
</ul>

Upvotes: -1

FRL
FRL

Reputation: 774

You can also override by your container

<div class="someclassintabscontainer">
<!-- Here the tabs code writed normaly -->
</div>

Write this in some css file.

.someclassintabscontainer .nav-tabs > li {
    float: right;
}

Upvotes: -1

Arya shrida
Arya shrida

Reputation: 9

To use right aligned tabs, just add .text-right to the .nav-tabs class.

<ul class="nav nav-tabs text-right nav-tabs-highlight ">

Upvotes: 0

ShSehati
ShSehati

Reputation: 508

use pull-right class:

<ul class="nav nav-tabs">
    <li class="active pull-right"><a href="#">Home</a></li>
    <li class="pull-right"><a href="#">Tab1</a></li>
    <li class="pull-right"><a href="#">Tab2</a></li>
</ul>

Upvotes: 24

Deepak Yadav
Deepak Yadav

Reputation: 7069

Create a new class for Right alignment and use below css.

/* overwrite boostrap */

.nav>li {
  float: none!important;
  display: inline-block!important;
}
/* new class */

.nav-tabs-right {
  text-align: right;
  font-size: 0;
  /* prevent floated child bug */
}
.nav-tabs-right>li {
  display: inline-block;
  clear: left;
  float: none;
  text-align: right;
  font-size: 12px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<div class="container jumbotron">

  <ul class="nav nav-tabs nav-tabs-right">
    <li class="active">
      <a data-toggle="tabs" href="#tab-1">Tab 1</a>
    </li>
    <li>
      <a data-toggle="tabs" href="#tab-2">Tab 2</a>
    </li>
  </ul>

</div>

Upvotes: 2

Christina
Christina

Reputation: 34652

Using .pull-right does this, it's undesirable:

enter image description here

What you want is this: enter image description here

You need to adjust some stuff:

http://jsbin.com/zuxol/1/

HTML

  <div class="right-tabs clearfix">
<ul class="nav nav-tabs">
  <li class="active"><a href="#tab_a" data-toggle="tab">Tab A</a></li>
  <li><a href="#tab_b" data-toggle="tab">Tab B</a></li>
  <li><a href="#tab_c" data-toggle="tab">Tab C</a></li>
  <li><a href="#tab_d" data-toggle="tab">Tab D</a></li>
</ul>
<div class="tab-content">
        <div class="tab-pane active" id="tab_a">
            <h4>Pane A</h4>
            <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames
                ac turpis egestas.</p>
        </div>
        <div class="tab-pane" id="tab_b">
            <h4>Pane B</h4>
            <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames
                ac turpis egestas.</p>
        </div>
        <div class="tab-pane" id="tab_c">
            <h4>Pane C</h4>
            <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames
                ac turpis egestas.</p>
        </div>
        <div class="tab-pane" id="tab_d">
            <h4>Pane D</h4>
            <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames
                ac turpis egestas.</p>
        </div>
</div><!-- tab content -->

</div><!-- end right-tabs -->  

CSS

.right-tabs .nav {
    float: right;
    border-bottom: 0px;
}
.right-tabs .nav li { float: left }
.right-tabs .tab-content {
    float: left;
    border-top: 1px solid #ddd;
    margin-top: -1px;
}

Upvotes: 19

Shawn Taylor
Shawn Taylor

Reputation: 15730

Use the class .navbar-right to push an element to the right within a navbar, or .pull-right to do the same when not in a navbar.

<ul class="nav nav-tabs navbar-right">
    <li class="active"><a href="#">Home</a></li>
    <li><a href="#">Tab1</a></li>
    <li><a href="#">Tab2</a></li>
</ul>

Good to know the other helper-classes here too: http://getbootstrap.com/css/#helper-classes

Upvotes: 31

Related Questions