Effective method for creating a responsive navbar

On my webpage, I have a navigation bar with three buttons on the left side and a search bar on the right side. While I attempted to write code to make them responsive for smaller screens, it seems that my approach was incorrect as they are still not responding as intended. I am currently exploring better methods to ensure their responsiveness. The goal is to create a page layout similar to the image shown below.

Check out the stackblitz link for more details

  .searchbar{
    width: 400px;
  }
    .btn-primary{
    background-color: #002B42;
    padding:10px;
    font-size: 12px;
    border-radius: 4px;
    margin-left: 3px;
    font-family: Arial, Helvetica, sans-serif;
  }
  .btn-light{
     margin-left: 30px; 
    padding:10px;

    background-color: transparent;
    border: none;
    color: black;
    font-size: 13px;
    outline: none;
  }
<nav class="navbar navbar-expand-md navbar-light fixed-top bg-light">

<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">&nbsp;&nbsp;SAVED LISTS</i></button>      </li>
      <li class="nav-item">
        <button class="btn btn-light"> <i class="fa fa-filter" aria-hidden="true">&nbsp;&nbsp; SAVED FILTER</i>  </button> 
      </li>     
      <li class="nav-item">
        <button class="btn btn-light"> <i class="fa fa-history" aria-hidden="true">&nbsp;&nbsp; SEARCH HISTORY</i>  </button> 
      </li>
    </ul>

  <div class="ml-auto">
    <input class="form-control searchbar" name="search" [(ngModel)]="search" type="search" placeholder="Search" />
  </div>
</nav

https://i.sstatic.net/soPfu.png

Answer №1

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">&nbsp;&nbsp;SAVED LISTS</i></button>      </li>
                <li class="nav-item">
                  <button class="btn btn-light"> <i class="fa fa-filter" aria-hidden="true">&nbsp;&nbsp; SAVED FILTER</i>  </button> 
                </li>     
                <li class="nav-item">
                  <button class="btn btn-light"> <i class="fa fa-history" aria-hidden="true">&nbsp;&nbsp; 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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the method for linking an icon in an iconfont using a keyword?

For my project, I would like to incorporate icon fonts and customize the font file using FontForge. I understand that glyphs can be referenced by unicode in HTML or CSS, for example <i>&#xe030;</i> and &::before{content: "\e030";} ...

Issue with NPM installation of node module

My angular project includes a package.json file with all the necessary dependencies listed. However, whenever I run "npm install" in the terminal, the packages seem to download correctly and a node module folder is created in my root directory. Strangely ...

Difficulty arises when using relative paths with XMLHttpRequest.send

Having difficulties with a basic task here. I'm in the process of creating a website without using a server, and I've hit a snag when it comes to accessing files via XMLHttpRequest. Looking at the example code provided below, you'll see tha ...

Retrieving HTML source code using PyGTK WebKit

Can anyone help me with this issue I am facing in my code? When I try to get the HTML source code of the current page, all I get is 'GString at 0x8875130'. How can I convert this into actual text that contains HTML? import gi gi.require_version( ...

Angular allows users to click on elements that have been dynamically added to the Document Object Model (DOM), such

Incorporating the ngx-bootstrap datepicker into my project was a game changer. I have a submit button positioned below the datepicker, and I have a specific goal in mind. I want the submit button to become active as soon as I select a date from the datepic ...

Whenever I press a button, my desire is for each picture to seamlessly reposition itself in the exact same spot on the screen

Having some issues with my code. When I click a button, the plan is for the pictures to change one by one to simulate a traffic light sequence. However, when I run the code, all the pictures appear at once without any effect from the button. Any help in ac ...

Create a dynamic webpage where two div elements glide in opposite directions

My apologies for this seemingly basic question, but I am wondering if anyone knows how to create an animation where a div moves up and down while scrolling, similar to the effect on this website: On that site, near the footer, there are 2 sections with 2 ...

Problem with Submitting Form using Search Bar

I've tried everything, but I can't seem to get this search form to submit. <div id="search_bar_container" style="z-index:99999"> <div class="container"> <form action="tour-list-search-results.php" method="post" name="searc ...

Bootstrap - the ability to resize elements dynamically

I'm currently working on a layout using Bootstrap and I could use some guidance to achieve the desired outcome. Essentially, what I am trying to accomplish is having resizable elements on the screen. When there's only one element, it should take ...

Personalizing Bootstrap Styles Using Sass

As a newcomer to Bootstrap 5 and Sass, I have been thoroughly enjoying the learning process. However, I have a couple of questions that have come up along the way... When it comes to customizing Bootstrap Sass, I understand the concept of variable overrid ...

Leveraging multiple routes for a single component in Angular 6

Creating a component named Dashboard for admin requires passing the username in the route to find user information. This is the routing setup: {path:'dashboard/:username',component:DashboardComponent,children:[ {path:'role',component: ...

What steps should I take to ensure my button remains intact and undamaged?

I'm encountering an issue with a CSS-styled button that appears distorted and displayed oddly across multiple lines when it is set as a link. However, if I change the button to an input element, it looks flawless. How can I ensure my link button displ ...

Strange behavior of focus()

My objective is to launch a popup containing an input field and automatically bring focus to that input. I have attempted using $('#input').focus(), $('#input').first().focus(), and $('#input')[0].focus(), but unfortunately, ...

Aligning images horizontally within individual div containers within a list

Struggling to align images horizontally, they are all stacked on top of each other. New to this and could use some assistance figuring it out! Any help would be appreciated! <div class="social"> <ul> <div class="facebook"> ...

How can I extract data from a link using Python?

Currently, I am working on a Python program to extract the rating of a movie from one of my preferred websites. Here’s an example link to a review: Right now, I am using string.partition commands to retrieve sections of the source HTML code that contai ...

Tips for conducting a simulated XSS attack on the login page

Login Page <html> <head> <title> Login </title> </head> <style> #footer { position:absolute; bottom:0; width:100%; height:60px; } </style> <body> <div class="container"> <form me ...

The crossbars in the JQuery plugin Lightbox are not visible

How can I make the cross bar show when clicking the icon to display an image using this code snippet? <link rel="stylesheet" href="css/lightbox.css"> <script src="js/lightbox.js"></script> <a href="images/gallery_image/Gallery_img.p ...

Does the sliding transition between views function properly, even though the view appears on top of the header and behind the footer

My angular app is running smoothly, but now I want to add animations between views. When a user clicks on a link in the navbar, I want the view to slide to a different one. I was inspired by this example: Sliding between views. However, when I implemented ...

Swap the image when hovering over it

Is it possible to modify this specific code so that a hover effect is triggered on mouseover? I attempted to look into similar questions and answers, but I found them difficult to understand. Here is the HTML snippet: <a href="RR.html"><img src ...

Tips on retaining input in fields after form submission for future modifications

Is it feasible to retain user input within a form field after the form has been submitted, enabling the user to modify the entry? I have an HTML registration form [with some JS validation], followed by a PHP file to insert data into SQL and simultaneously ...