user11508332
user11508332

Reputation: 667

cannot see navbar options when clicking on hamburger/bars menu on mobile screen

For the following code in html (showing a navbar), when I reduce the width of the page enough such that the hamburger/bars icon appears instead of the normal options in the navbar, I cannot see the original options when I click on the hamburger/bars icon (top right) and nothing happens - does anyone know how I'd be able to fix this so I can see the options?

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <link href="https://fonts.googleapis.com/css?family=Nunito&display=swap" rel="stylesheet">
    <style>
        * {
            margin: 0px;
            padding: 0px;
            font-family: 'Nunito', sans-serif;
        }

        .menu-bar {
            background-image: linear-gradient(-90deg, #d38312, #a83279)
        }

        .nav-link {
            font-size: 16px;
            margin: 3px;
            color: #fff!important;
            font-weight: 500;
        }

        .navbar-nav {
            text-align: right;
            margin-right: 20px;
        }

        .menu-bar .navbar-toggler {
            padding-right: 20px;
            outline: none!important;
            border: none!important;
        }

        .navbar .fa {
            color: #fff!important;
            font-size: 26px;
        }

        .nav-link:hover {
            font-weight: 600;
            border-bottom: 1px solid #fff;
        }

        .navbar-brand img {
            width: 150px;
            margin-top: 5px;
            margin-left: 20px; 
        }

        @media only screen and (max-width: 1000px) {
            .nav-link:hover {
                border-bottom: none!important;
            }
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="menu-bar">
            <nav class="navbar navbar-expand-lg navbar-light">
                <a class="navbar-brand" href="#">Navbar</a> 
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                  <i class="fa fa-bars"></i>
                </button>
                <div class="collapse navbar-collapse" id="navbarNav">
                  <ul class="navbar-nav ml-auto">
                    <li class="nav-item">
                      <a class="nav-link" href="#">Home</a>
                    </li>
                    <li class="nav-item">
                      <a class="nav-link" href="#">Services</a>
                    </li>
                    <li class="nav-item">
                      <a class="nav-link" href="#">Offers</a>
                    </li>
                    <li class="nav-item">
                      <a class="nav-link" href="#">Help</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Contact</a>
                    </li>
                  </ul>
                </div>
              </nav>
        </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
</body>
</html>

Upvotes: 1

Views: 40

Answers (1)

Anwar Hossen
Anwar Hossen

Reputation: 584

Because you are using Bootstrap-5 which is still beta version. Use Bootstrap-4 from this link - https://getbootstrap.com/docs/4.5/getting-started/introduction/

Here is the working code -

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <link href="https://fonts.googleapis.com/css?family=Nunito&display=swap" rel="stylesheet">
    <style>
        * {
            margin: 0px;
            padding: 0px;
            font-family: 'Nunito', sans-serif;
        }

        .menu-bar {
            background-image: linear-gradient(-90deg, #d38312, #a83279)
        }

        .nav-link {
            font-size: 16px;
            margin: 3px;
            color: #fff!important;
            font-weight: 500;
        }

        .navbar-nav {
            text-align: right;
            margin-right: 20px;
        }

        .menu-bar .navbar-toggler {
            padding-right: 20px;
            outline: none!important;
            border: none!important;
        }

        .navbar .fa {
            color: #fff!important;
            font-size: 26px;
        }

        .nav-link:hover {
            font-weight: 600;
            border-bottom: 1px solid #fff;
        }

        .navbar-brand img {
            width: 150px;
            margin-top: 5px;
            margin-left: 20px; 
        }

        @media only screen and (max-width: 1000px) {
            .nav-link:hover {
                border-bottom: none!important;
            }
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="menu-bar">
            <nav class="navbar navbar-expand-lg navbar-light">
                <a class="navbar-brand" href="#">Navbar</a> 
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                  <i class="fa fa-bars"></i>
                </button>
                <div class="collapse navbar-collapse" id="navbarNav">
                  <ul class="navbar-nav ml-auto">
                    <li class="nav-item">
                      <a class="nav-link" href="#">Home</a>
                    </li>
                    <li class="nav-item">
                      <a class="nav-link" href="#">Services</a>
                    </li>
                    <li class="nav-item">
                      <a class="nav-link" href="#">Offers</a>
                    </li>
                    <li class="nav-item">
                      <a class="nav-link" href="#">Help</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">Contact</a>
                    </li>
                  </ul>
                </div>
              </nav>
        </div>
    </div>
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
</body>
</html>

The data-* attributes have been replaced with data-bs-* in Bootstrap 5. So for Bootstrap 5, the code will be like this-

<button class="navbar-toggler" data-bs-toggle="collapse" data-bs-target="#navbar">
<span class="navbar-toggler-icon"></span>

Upvotes: 1

Related Questions