Bootstrap snippet and html example. Navbar Topnav with submenu

This html snippet was created to help web designers, web developers, front-end and back-end developer save time. Use it for free in your project and build your app faster, You can also download the HTML, CSS, and JS code.

HTML code

This is the html code used to create this bootstrap snippet, You can copy and paste the following html code inside a page with bootstrap 4.0.0 included, to get the result that you can see in the preview selection



<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<div class="container">
    <!-- Static navbar -->
    <nav class="navbar navbar-expand-md navbar-dark bg-dark">
        <a class="navbar-brand" href="#">Navbar</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse justify-content-md-end" id="navbarNavDropdown">
            <ul class="navbar-nav">
                <li class="nav-item dropdown active">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Home<span class="sr-only">(current)</span></a>
                    <ul class="dropdown-menu dropdown-menu-right sub-menu-left" aria-labelledby="navbarDropdownMenuLink">
                        <li><a class="dropdown-item" href="#">Action 1</a></li>
                        <li><a class="dropdown-item" href="#">Action 2</a></li>
                        <li><a class="dropdown-item" href="#">Action 3</a></li>
                        <li><a class="dropdown-item dropdown-toggle" href="#">Submenu 1</a>
                            <ul class="dropdown-menu sub-menu-left">
                                <li><a class="dropdown-item" href="#">Submenu 1 Action 1</a></li>
                                <li><a class="dropdown-item" href="#">Submenu 1 Action 2</a></li>
                                <li><a class="dropdown-item" href="#">Submenu 1 Action 3</a></li>
                            </ul>
                        </li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Features</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Pricing</a>
                </li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Contact Us</a>
                    <ul class="dropdown-menu dropdown-menu-right sub-menu-left" aria-labelledby="navbarDropdownMenuLink">
                        <li><a class="dropdown-item" href="#">Action 1</a></li>
                        <li><a class="dropdown-item" href="#">Action 2</a></li>
                        <li><a class="dropdown-item" href="#">Action 3</a></li>
                        <li><a class="dropdown-item dropdown-toggle" href="#">Submenu 1</a>
                            <ul class="dropdown-menu sub-menu-left">
                                <li><a class="dropdown-item" href="#">Submenu 1 Action 1</a></li>
                                <li><a class="dropdown-item" href="#">Submenu 1 Action 2</a></li>
                                <li><a class="dropdown-item" href="#">Submenu 1 Action 3</a></li>
                            </ul>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </nav>
</div>
<!-- /container -->

CSS code

This is the css code used to create this bootstrap snippet, You can copy and paste the following css code inside a page with bootstrap 4.0.0 included, to get the result that you can see in the preview selection



body{margin-top:20px;}

.navbar-light .navbar-nav .nav-link {
    color: rgb(64, 64, 64);
}
.btco-menu li > a {
    padding: 10px 15px;
    color: #000;
}
.btco-menu .active a:focus,
.btco-menu li a:focus ,
.navbar > .show > a:focus{
    background: transparent;
    outline: 0;
}
.dropdown-menu .show > .dropdown-toggle::after{
    transform: rotate(-90deg);
}

Javascript/Jquery code

This is the javascript code used to create this bootstrap snippet, You can copy and paste the following javascript code inside a page with bootstrap 4.0.0 included, to get the result that you can see in the preview selection




$( document ).ready( function () {
    $( '.dropdown-menu a.dropdown-toggle' ).on( 'click', function ( e ) {
        var $intWidth = 0;
        var $el = $( this );
        var $parent = $( this ).offsetParent( ".dropdown-menu" );
        if ( !$( this ).next().hasClass( 'show' ) ) {
            $( this ).parents( '.dropdown-menu' ).first().find( '.show' ).removeClass( "show" );
        }
        var $subMenu = $( this ).next( ".dropdown-menu" );
        $subMenu.toggleClass( 'show' );
        $( this ).parent( "li" ).toggleClass( 'show' );
        $( this ).parents( 'li.nav-item.dropdown.show' ).on( 'hidden.bs.dropdown', function ( e ) {
            $( '.dropdown-menu .show' ).removeClass( "show" );
        } );
        if ( $parent.hasClass( 'sub-menu-left' ) ) {
        	$intWidth = $parent.outerWidth() - $parent.outerWidth() - $parent.outerWidth() + 4;
        }
        if ( $parent.hasClass( 'sub-menu-right' ) ) {
        	$intWidth = $parent.outerWidth() - 4;
        }
         if ( !$parent.parent().hasClass( 'navbar-nav' ) ) {
                $el.next().css( { "top": $el[0].offsetTop - 11, "left": $intWidth } );
        }
        return false;
    } );
} );
 

Similar snippets

Bootstrap example and template. Jobs tabs

Jobs tabs

Bootstrap example and template. user blog post widget

user blog post widget

Bootstrap example and template. bs4 social friends

bs4 social friends

Bootstrap example and template. Count Menu (no responsive)

Count Menu (no responsive)

Bootstrap example and template. bs5 dark footer

bs5 dark footer

Bootstrap example and template. Whatsapp web chat template

Whatsapp web chat template

Bootstrap example and template. candidate list with skills rating and location

candidate list with skills rating and location

Bootstrap example and template. Features

Features

Bootstrap example and template. Navbar Topnav with submenu

About this bootstrap example/template

We hope you will enjoy this awesome snippet and stay tuned for the latest updates, bootdey snippets are already used in thousands of blogs, websites and projects. We believe it will save your precious time and gives trendy look to your next web project.

We always try to offer the best beautiful and responsive source of Bootstrap code examples and components.

This code example currectly have 987 views, Using this bootstrap snippet you have the following benefits:

Bootstrap 4.0.0

<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css'>

<script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js'></script>

This code example is based on bootstrap 4.0.0 and the grid system of this framework

Responsive

Based on bootstrap framework makes all the layouts perfectly responsive for all devices

Crossbrowser compatibility

Tested on all major browsers, it works smoothly on all of them

Jquery plugins

Great built-in plugins with jquery framework, you can easy to change all declarations

semantic html 5

Built on html / css3 the code quality is really amazing

Simple Integration

This code example can be simply integrated on existing sites and new ones too, all you need to do is copy the code and start working