2

I'm using this template and I would like to make the sub-menu, but I don't have the Bootstrap knowledge so I am struggling to recreate it. Can you help with that?

I wanna know how to create the sub-menu in the following code.

My code:

Html:

<div class="collapse navbar-collapse">
  <ul class="nav pull-right navbar-nav">
    <li> 
    <a class="MainMenub" href="#service" >Company</a>
    <ul>
      <li> <a href="#">Sub Menu 1</a>  </li>
    </ul>
    </li>
  </ul>
</div> 

CSS:

#header .navbar {
    background: #2e3949;
    border-radius: 0px;
    margin-bottom: 0px;
}
#header{
    background: #2e3949;
}
#header .topnavbar {
    height: 100px; 
}
#header .navbar-header a {
    font-family: "Pacifico", Sans-serif;
    font-size: 2.2em;
    color: white;
    line-height: 60px; 
}

#header .navbar-toggle, #header .nav {
    margin-top: 35px; 
}

#header .navbar-fixed-top .navbar-toggle, 
#header .navbar-fixed-top .nav {
    margin-top: 15px; 
}
#header .navbar-fixed-top  .navbar-header a {
    line-height: 30px; 
    text-decoration: none;
}

#header .navbar-nav .active a,
#header .navbar-nav a:hover {
    background-color: #e96269;
}

#header .navbar-nav a,
#header .navbar-nav .active a {
    font-family: "PT Sans";
    font-weight: bold;
    padding: 5px 20px;
    margin-right: 5px;
    border-radius: 15px;
    color: white;
    font-size: 1.25em;
}

#header .navbar-nav a {
    background-color: #2e3949;

    -webkit-transition: background-color .2s;
    -moz-transition: background-color .2s;
    -o-transition: background-color .2s;
    -ms-transition: background-color .2s;
    transition: background-color .2s;
}

#header .navbar-nav .active a:hover {
    background-color: #fb3c46;

    -webkit-transition: background-color .2s;
    -moz-transition: background-color .2s;
    -o-transition: background-color .2s;
    -ms-transition: background-color .2s;
    transition: background-color .2s;
}
#header .navbar-nav a:active {
    background-color: red;
}
#header .navbar-header i {
    font-weight: bold;
    color: white;
    font-size: 1.5em;
}

#header .navbar.topnavbar {
    -webkit-animation: movetextdown 500ms ease;
    -moz-animation: movetextdown 500ms ease;
    -ms-animation: movetextdown 500ms ease;
    -o-animation: movetextdown 500ms ease;
    animation: movetextdown 500ms ease;
}

#header .navbar-fixed-top.navbar {
    -webkit-animation: moveBottom 500ms ease;
    -moz-animation: moveBottom 500ms ease;
    -ms-animation: moveBottom 500ms ease;
    -o-animation: moveBottom 500ms ease;
    animation: moveBottom 500ms ease;
}

Menu View:

enter image description here

smathy
  • 26,283
  • 5
  • 48
  • 68
Lemon
  • 82
  • 1
  • 13

2 Answers2

2

Use this code for sub-menu:

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
    <ul class="nav navbar-nav navbar-right">
        <li><a href="#" class="active">Company</a></li>
        <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Sub Menu 1<span class="caret"></span></a>
            <ul class="dropdown-menu" role="menu">
                <li><a href="#">Option 1</a></li>
                <li><a href="#">Option 2</a></li>
                <li><a href="#">Option 3</a></li>
            </ul>
        </li>
    </ul>
</div>

Dont forget to add boostrap libraries:

  <link rel="stylesheet" href="css/bootstrap.min.css">
  <script type="text/javascript" src="js/bootstrap.min.js"></script>

For two columns sub-menu use following html:

<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Sub Menu 1<span class="caret"></span></a>
    <ul class="dropdown-menu" role="menu">
    <div class="col-md-6">
        <li><a href="#">Option 1</a></li>
        <li><a href="#">Option 2</a></li>
        <li><a href="#">Option 3</a></li>
    </div>
    <div class="col-md-6">
        <li><a href="#">Option 4</a></li>
        <li><a href="#">Option 5</a></li>
        <li><a href="#">Option 6</a></li>
    </div>
    </ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Sub Menu 2<span class="caret"></span></a>
    <ul class="dropdown-menu" role="menu">
        <li><a href="#">Option 1</a></li>
        <li><a href="#">Option 2</a></li>
        <li><a href="#">Option 3</a></li>
    </ul>
</li>

Probably you will need wider dropdown for two columns:

.dropdown-menu {
    min-width:250px;
}
Kamil
  • 1,987
  • 16
  • 14
  • Sure, just go there -> [link](http://stackoverflow.com/questions/8878033/how-to-make-twitter-bootstrap-menu-dropdown-on-hover-rather-than-click) and check the solution. – Kamil Aug 27 '14 at 16:48
  • Of course :) simply go to this website and check it out! --> [multi level menu](http://bootsnipp.com/snippets/featured/multi-level-dropdown-menu-bs3) – Kamil Aug 27 '14 at 17:01
  • I have updated the menu view. I meant two column view. could you please look the bottom of my description. – Lemon Aug 27 '14 at 17:10
  • I also updated my answer, hope this is what you want. – Kamil Aug 27 '14 at 17:28
  • Suubmenu 1 should contain the two column view menu. see the www.puthuvannam.com under the company menu. – Lemon Aug 27 '14 at 17:56
  • Updated again :) check it out please – Kamil Aug 27 '14 at 19:45
  • Sorry for disturbing again and again. How to auto width the sub menu width. please. – Lemon Aug 28 '14 at 03:25
1

Here is a demo: http://jsbin.com/bixiwu/1 You need to assign the class "dropdown-menu" and the role "menu". Bootstrap documentation will be of a lot of help: bar

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Link</a></li>
        <li><a href="#">Link</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
          <ul class="dropdown-menu" role="menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li class="divider"></li>
            <li><a href="#">Separated link</a></li>
            <li class="divider"></li>
            <li><a href="#">One more separated link</a></li>
          </ul>
        </li>
      </ul>
</div>
Diego
  • 916
  • 1
  • 13
  • 36