Solution 1 :

You have some flaws…

1 – Need to add plugin jQuery before bootstrap plugin:

...
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
...
  

2 – You have specified closing tags for metatags. Metatags have no end tags.

It is not right:

<meta name="viewport" content="width=device-width, initial-scale=1"></meta>

It is right. Without </meta>:

<meta name="viewport" content="width=device-width, initial-scale=1">

3 – Remove the height rule height: 54px.

<!DOCTYPE html>
<html>
   <head>
       <title>Bootstrap Resize</title>
       <meta charset="utf-8">
       <meta name="viewport" content="width=device-width, initial-scale=1" >
       <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" />
       <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
       <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
      
   </head>
   <style type="text/css">
   
   .navbar-custom {
     background-color: #484848;
   }

   </style>

   <body>                 
    <nav class="navbar navbar-custom navbar-expand-lg navbar-dark fixed-top" id="mainNav">
      <div class="container">
        <a  style="font: 20px Arial,sans-serif" class="navbar-brand js-scroll-trigger" href="#">HOME</a>
        <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navbarResponsive">
          <ul style="font: 15px Roboto,sans-serif" class="navbar-nav ml-auto">
            <li class="nav-item">
              <a class="nav-link js-scroll-trigger" href="#about">LOREM</a>
            </li>
            <li class="nav-item">
              <a class="nav-link js-scroll-trigger" href="#expertise">LOREM</a>
            </li>
            <li class="nav-item">
              <a class="nav-link js-scroll-trigger" href="#portfolio">LOREM</a>
            </li>
            <li class="nav-item">
              <a class="nav-link js-scroll-trigger" href="#contact">LOREM</a>
            </li>
          </ul>
        </div>

      </div>
    </nav>
   </body>
</html>

Problem :

I am using bootstrap 4. The navbar looks like this on a large screen:
enter image description here
However, after it collapses on a small screen, it doesn’t show the menu option when I click the menu button:
enter image description here

On a small screen, it should list the menu options once the button is clicked. How can I fix this issue? Here is my HTML and CSS code:

<!DOCTYPE html>
<html>
   <head>
       <title>Bootstrap Resize</title>
       <meta charset="utf-8"></meta>
       <meta name="viewport" content="width=device-width, initial-scale=1" ></meta>
       <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" />
       <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
      
   </head>
   <style type="text/css">
    .navbar-custom {
     height: 54px; 
     background-color: #484848;
   }
   </style>

   <body>                 
    <nav class="navbar navbar-custom navbar-expand-lg navbar-dark fixed-top" id="mainNav">
      <div class="container">
        <a  style="font: 20px Arial,sans-serif" class="navbar-brand js-scroll-trigger" href="#">HOME</a>
        <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navbarResponsive">
          <ul style="font: 15px Roboto,sans-serif" class="navbar-nav ml-auto">
            <li class="nav-item">
              <a class="nav-link js-scroll-trigger" href="#about">LOREM</a>
            </li>
            <li class="nav-item">
              <a class="nav-link js-scroll-trigger" href="#expertise">LOREM</a>
            </li>
            <li class="nav-item">
              <a class="nav-link js-scroll-trigger" href="#portfolio">LOREM</a>
            </li>
            <li class="nav-item">
              <a class="nav-link js-scroll-trigger" href="#contact">LOREM</a>
            </li>
          </ul>
        </div>

      </div>
    </nav>
   </body>
</html>

Comments

Comment posted by Mx.

I tried your code, but it leaves a white space on the left and right side when the dropdown menu is expanded on a small screen.

Comment posted by Mx.

When I try to run your code, it also leaves a whitespace on the left and right side when the dropdown menu is expanded

Comment posted by Mx.

Thanks, but I need the background color of the navbar to be #484848

Comment posted by s.kuznetsov

@Mx., I figured out what the problem is. And returned the default code. The problem was in rule

Comment posted by Mx.

If I remove, height: 54px, then the navbar becomes wider. I need the navbar height to be at 54px.

By