Bootstrap Tutorial - Create Side Navbar








The following code shows how to create Side Navbar.

Example

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-2.0.2.js'></script>
<link rel="stylesheet" type="text/css"
  href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<script type='text/javascript'
  src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css"
  href="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css">
<style type='text/css'>
.group {<!--from   w  w  w.  j a  va2  s.co m-->
  background: yellow;
  width: 200px;
  height: 500px;
}
.group .subgroup {
  background: orange;
  width: 150px;
  height: 200px;
}
.fixed {
  position: fixed;
}
.bs-docs-sidebar.affix {
  position: static;
}
@media ( min-width :768px) {
  .bs-docs-sidebar {
    padding-left: 20px;
  }
}
.bs-docs-sidenav {
  margin-top: 20px;
  margin-bottom: 20px;
}

.bs-docs-sidebar .nav>li>a {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #999;
  padding: 4px 20px;
}

.bs-docs-sidebar .nav>li>a:hover, .bs-docs-sidebar .nav>li>a:focus {
  padding-left: 19px;
  color: #563d7c;
  text-decoration: none;
  background-color: transparent;
  border-left: 1px solid #563d7c;
}

.bs-docs-sidebar .nav>.active>a, .bs-docs-sidebar .nav>.active:hover>a,
  .bs-docs-sidebar .nav>.active:focus>a {
  padding-left: 18px;
  font-weight: 700;
  color: #563d7c;
  background-color: transparent;
  border-left: 2px solid #563d7c;
}

.bs-docs-sidebar .nav .nav {
  display: none;
  padding-bottom: 10px;
}

.bs-docs-sidebar .nav .nav>li>a {
  padding-top: 1px;
  padding-bottom: 1px;
  padding-left: 30px;
  font-size: 12px;
  font-weight: 400;
}

.bs-docs-sidebar .nav .nav>li>a:hover, .bs-docs-sidebar .nav .nav>li>a:focus
  {
  padding-left: 29px;
}

.bs-docs-sidebar .nav .nav>.active>a, .bs-docs-sidebar .nav .nav>.active:hover>a,
  .bs-docs-sidebar .nav .nav>.active:focus>a {
  font-weight: 500;
  padding-left: 28px;
}

.bs-docs-sidebar .nav>.active>ul {
  display: block;
}

.bs-docs-sidebar.affix, .bs-docs-sidebar.affix-bottom {
  width: 213px;
}

.bs-docs-sidebar.affix {
  position: fixed;
  top: 20px;
}

.bs-docs-sidebar.affix-bottom {
  position: absolute;
}

.bs-docs-sidebar.affix-bottom .bs-docs-sidenav, .bs-docs-sidebar.affix .bs-docs-sidenav
  {
  margin-top: 0;
  margin-bottom: 0;
}

@media ( min-width :1200px) {
  .bs-docs-sidebar.affix-bottom, .bs-docs-sidebar.affix {
    width: 263px;
  }
}

.bs-docs-section {
  margin-bottom: 60px;
}

.bs-docs-section:last-child {
  margin-bottom: 0;
}

.nav li.active>a {
  color: #563d7c;
}
</style>
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
$('body').scrollspy({
    target: '#sidebar'
});
});//]]>  
</script>
</head>
<body>
  <div class="row">
    <nav class="col-xs-3 bs-docs-sidebar hidden-print">
      <ul class="nav nav-stacked bs-docs-sidenav fixed" id="sidebar">
        <li><a href="#Group1">Group 1</a>
          <ul class="nav nav-stacked" id="sidebar">
            <li><a href="#Group1Sub1">Sub-Group 1</a></li>
            <li><a href="#Group1Sub2">Sub-Group 2</a></li>
          </ul></li>
        <li><a href="#Group2">Group 2</a>
          <ul class="nav nav-stacked" id="sidebar">
            <li><a href="#Group2Sub1">Sub-Group 1</a></li>
            <li><a href="#Group2Sub2">Sub-Group 2</a></li>
          </ul></li>
        <li><a href="#Group3">Group 3</a>
          <ul class="nav nav-stacked" id="sidebar">
            <li><a href="#Group3Sub1">Sub-Group 1</a></li>
            <li><a href="#Group3Sub2">Sub-Group 2</a></li>
          </ul></li>
      </ul>
    </nav>
    <div class="col-xs-9">
      <section id="Group1" class="group">
        <h3>Group 1</h3>
        <div id="Group1Sub1" class="subgroup">
          <h4>Group 1 Sub 1</h4>
        </div>
        <div id="Group1Sub2" class="subgroup">
          <h4>Group 1 Sub 2</h4>
        </div>
      </section>
      <section id="Group2" class="group">
        <h3>Group 2</h3>
        <div id="Group2Sub1" class="subgroup">
          <h4>Group 2 Sub 1</h4>
        </div>
        <div id="Group2Sub2" class="subgroup">
          <h4>Group 2 Sub 2</h4>
        </div>
      </section>
      <section id="Group3" class="group">
        <h3>Group 3</h3>
        <div id="Group3Sub1" class="subgroup">
          <h4>Group 3 Sub 1</h4>
        </div>
        <div id="Group3Sub2" class="subgroup">
          <h4>Group 3 Sub 2</h4>
        </div>
      </section>
    </div>
  </div>
  <!-- Post Info -->
  <div
    style='position: fixed; bottom: 0; left: 0; background: lightgray; width: 100%;'>
    Fork This Skeleton Here <a href='http://jsfiddle.net/KyleMit/kcpma/'>Bootrsap
      3.0 Skeleton</a><br />
    <div>
</body>
</html>

Click to view the demo