Initially, there is no need to specify the width 400px
for the .searchbar
class.
Instead, use a media query to adjust the navbar for smaller screen sizes, enhancing user experience.
In my view, it's best to follow Bootstrap's recommended approach.
Place your
<ul class="navbar-nav mr-auto">
inside
<div class="collapse navbar-collapse" id="my-navbar">
and include a button as the navbar toggler.
Substitute the
ml-auto
class with
my-2 my-md-0
for the search wrapper as shown below:
body{
padding-top: 60px;
}
.search-wrapper{
flex-grow: 1;
}
.btn-primary{
background-color: #002B42;
font-size: 12px;
border-radius: 4px;
font-family: Arial, Helvetica, sans-serif;
}
.btn-light{
background-color: transparent;
border: none;
color: black;
font-size: 13px;
outline: none;
}
.items{
margin-top: ;
}
@media only screen and (max-width: 768px) {
body{
padding-top: 0!important;
}
.navbar{
position: relative;
}
.navbar-nav{
align-items: center;
margin: 15px 0;
}
.nav-item{
margin:10px 0;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="style.css">
<title>Document</title></head>
<body>
<nav class="navbar navbar-expand-md navbar-light fixed-top bg-light">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#my-navbar" aria-controls="my-navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="my-navbar">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<button type="button" class="btn btn-primary"><i class="fa fa-bars" aria-hidden="true"> SAVED LISTS</i></button> </li>
<li class="nav-item">
<button class="btn btn-light"> <i class="fa fa-filter" aria-hidden="true"> SAVED FILTER</i> </button>
</li>
<li class="nav-item">
<button class="btn btn-light"> <i class="fa fa-history" aria-hidden="true"> SEARCH HISTORY</i> </button>
</li>
</ul>
</div>
<div class="my-2 my-md-0 search-wrapper">
<input class="form-control searchbar" name="search" [(ngModel)]="search" type="search" placeholder="Search" />
</div>
</nav>
<div class="items">
<ol>
<li>dhsiudshdsds</li>
<li>dhsiudshdsds</li>
<li>dhsiudshdsds</li>
<li>dhsiudshdsds</li>
<li>dhsiudshdsds</li>
<li>dhsiudshdsds</li>
<li>dhsiudshdsds</li>
<li>dhsiudshdsds</li>
<li>dhsiudshdsds</li>
<li>dhsiudshdsds</li>
<li>dhsiudshdsds</li>
<li>dhsiudshdsds</li>
<li>dhsiudshdsds</li>
<li>dhsiudshdsds</li>
<li>dhsiudshdsds</li>
<li>dhsiudshdsds</li>
<li>dhsiudshdsds</li>
<li>dhsiudshdsds</li>
</ol>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>