Bootstrap Tutorial - Create sub tabs








The following code shows how to create sub tabs.

Example

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<style type='text/css'>
@import url('http://cdn-www.synonym.com/assets/css/bootstrap.min.css');
li {<!--from  w ww . j a v  a2  s . c  o  m-->
  font-weight: bold;
  font-size: 18px;
  background-color: #EEE;
}
.nav-tabs>li>a {
  padding-right: 30px;
  padding-left: 30px;
}
.nav-pills>li>a {
  padding-right: 20px;
  padding-left: 20px;
}
</style>
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
    document.getElementById('subHeaderTabAnswers').style.visibility = 'collapse';
    $('ul.nav-tabs li a').click(function (e) {
        $('ul.nav-tabs li.active').removeClass('active')
        $(this).parent('li').addClass('active')
    })
    $('ul.nav-pills li a').click(function (e) {
        $('ul.nav-pills li.active').removeClass('active')
        $(this).parent('li').addClass('active')
    })
    $(".ans-tab").click(function() {    
        document.getElementById('subHeaderTabAnswers').style.visibility = 'visible';
    });
    $(".topTab").click(function() {    
        document.getElementById('subHeaderTabAnswers').style.visibility = 'collapse';
    });
});
</script>
</head>
<body>
  <div id="headerTab">
    <ul class="nav nav-tabs">
      <li class="active ans-tab"><a href="#">Answers</a></li>
      <li class="topTab"><a href="#">Ask</a></li>
      <li class="topTab"><a href="#">Leaderboards</a></li>
    </ul>
  </div>
  <div id="subHeaderTabAnswers">
    <ul class="nav nav-pills">
      <li class="active"><a href="#">Top</a></li>
      <li><a href="#">Recent</a></li>
      <li><a href="#">Popular</a></li>
      <li><a href="#">Categories</a></li>
    </ul>
  </div>
</body>
</html>

Click to view the demo