mbilal25tr
mbilal25tr

Reputation: 141

Bootstrap 4 - Navbar won't collapse

I have no idea why it isn't working. I even tried to copy and paste the button and div tags from the examples in bootstrap's web site. I thought it has something to with the social media icons part. I turned them into comment lines but didn't work. Do you see my mistake?

Sorry if this is a repeat. I found questions with same title but they didn't help.

Thanks...

<!doctype html>
<html lang="tr">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

    <title>This is a page</title>
</head>
<body>

    <nav class="navbar navbar-expand bg-faded" style="background-color: #233042;">
        <div class="container">

            <img class="navbar-brand" width="130" src="http://via.placeholder.com/200x50">
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#menu">
                <i class="fas fa-bars"></i>
            </button>
            
            <div class="collapse navbar-collapse" id="menu">
                <ul class="navbar-nav mx-auto">
                    <li class="nav-item">
                        <a class="nav-link text-light" href="#">Anasayfa</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link text-light" href="#">Ürünlerimiz</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link text-light" href="#">Hizmetlerimiz</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link text-light" href="#">Hakkımızda</a>
                    </li>
                </ul>
            </div>

            <ul class="navbar-nav justify-content-end">
                <li class="nav-item">
                    <a class="nav-link text-light" href="#" target="_blank"><i class="fab fa-twitter fa-lg"></i></a>
                </li>
                <li class="nav-item">
                    <a class=" nav-link text-light" href="#" target="_blank"><i class="fab fa-facebook-f fa-lg"></i></a>
                </li>
                <li class="nav-item">
                    <a class=" nav-link text-light" href="#" target="_blank"><i class="fab fa-instagram fa-lg"></i></a>
                </li>
            </ul>

        </div>
    </nav>

    <!-- Optional JavaScript -->
    <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>
    <script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
</body>
</html>

Upvotes: 1

Views: 1209

Answers (1)

Klooven
Klooven

Reputation: 3926

You are using the class navbar-expand, which means that it never collapses. Just change it to navbar-expand-sm, and it will collapse on small screens.

Check the docs for more info.

Upvotes: 1

Related Questions