Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title>Bootstrap Navbar with Search Box in Dropdown</title> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Varela+Round"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"> <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script> <style> body { font-family: 'Varela Round', sans-serif; } .form-control { box-shadow: none; border-radius: 4px; } .navbar { background: #fff; padding-left: 16px; padding-right: 16px; border-bottom: 1px solid #dfe3e8; border-radius: 0; } .navbar .navbar-brand { padding-left: 0; font-size: 20px; padding-right: 50px; } .navbar .navbar-brand b { font-weight: bold; color: #eb5844; } .navbar .navbar-nav > a { margin: 0 0.25rem; } .navbar a, .navbar a:active { color: #888; font-size: 15px; background: transparent; } .navbar a:hover, .navbar a:focus { color: #f08373; } .navbar .navbar-nav.show > a, .navbar .navbar-nav > a.active { color: #eb5844 !important; background: transparent !important; } .search-box { width: 100%; position: relative; } .search-box input { border-color: #dfe3e8; box-shadow: none } .search-box input, .search-box .btn { min-height: 38px; border-radius: 2px; } .input-group-append .btn, .input-group-append .btn:active { border-color: #eb5844; background: #eb5844 !important; } .navbar .nav-item i { font-size: 18px; line-height: 16px; } .navbar .search-dropdown .dropdown-toggle::after { display: none; } .navbar .dropdown-menu { border-radius: 1px; border-color: #e5e5e5; box-shadow: 0 2px 8px rgba(0,0,0,.05); } .navbar .dropdown-menu a { padding: 6px 20px; } .navbar .search-dropdown .dropdown-menu { width: 400px; padding: 20px; left: auto; right: 0; font-size: 14px; } @media (max-width: 768px){ .navbar .navbar-right .dropdown-menu { width: 100%; background: transparent; padding: 10px 20px; } .navbar .input-group { width: 100%; } } </style> <script> $(document).ready(function(){ var dropdown = $(".search-dropdown"); var toogleBtn = $(".search-dropdown .dropdown-toggle"); // Toggle search and close icon for search dropdown dropdown.on("show.bs.dropdown", function(e){ toogleBtn.toggleClass("d-none"); }); dropdown.on("hide.bs.dropdown", function(e){ toogleBtn.addClass("d-none"); toogleBtn.first().removeClass("d-none"); }); }); </script> </head> <body> <nav class="navbar navbar-expand-lg"> <a href="#" class="navbar-brand">Brand<b>Name</b></a> <button type="button" class="navbar-toggler" data-toggle="collapse" data-target="#navbarCollapse"> <span class="navbar-toggler-icon"></span> </button> <!-- Collection of nav links, forms, and other content for toggling --> <div id="navbarCollapse" class="collapse navbar-collapse justify-content-start"> <div class="navbar-nav"> <a href="#" class="nav-item nav-link">Home</a> <a href="#" class="nav-item nav-link">About</a> <div class="nav-item dropdown"> <a href="#" data-toggle="dropdown" class="nav-item nav-link dropdown-toggle">Services</a> <div class="dropdown-menu"> <a href="#" class="dropdown-item">Web Design</a> <a href="#" class="dropdown-item">Web Development</a> <a href="#" class="dropdown-item">Graphic Design</a> <a href="#" class="dropdown-item">Digital Marketing</a> </div> </div> <a href="#" class="nav-item nav-link active">Pricing</a> <a href="#" class="nav-item nav-link">Blog</a> <a href="#" class="nav-item nav-link">Contact</a> </div> <div class="navbar-nav ml-auto"> <div class="nav-item dropdown search-dropdown"> <a data-toggle="dropdown" class="nav-item nav-link dropdown-toggle" href="#"><i class="fa fa-search"></i></a> <a data-toggle="dropdown" class="nav-item nav-link dropdown-toggle d-none" href="#"><i class="fa fa-close"></i></a> <div class="dropdown-menu"> <div> <form> <div class="input-group search-box"> <input type="text" id="search" class="form-control" placeholder="Search here..."> <div class="input-group-append"> <button type="button" class="btn btn-primary"><i class="fa fa-search"></i></button> </div> </div> </form> </div> </div> </div> <a href="#" class="nav-item nav-link"><i class="fa fa-facebook"></i></a> <a href="#" class="nav-item nav-link"><i class="fa fa-twitter"></i></a> <a href="#" class="nav-item nav-link"><i class="fa fa-google-plus"></i></a> <a href="#" class="nav-item nav-link"><i class="fa fa-pinterest-p"></i></a> </div> </div> </nav> </body> </html>