What is wrong with my code - help please

Hi there,

I am doing the codecademy bootstrap project “adhoc”. For some reason my navbar button won’t display the links when collapsed. I would appreciate your help. Here’s my code.

    <nav class="navbar navbar-light navbar-expand-md bg-light">
        <a class="navbar-brand"><img
                alt="AdHoc Logo" height="30">
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
            <span class="navbar-toggler-icon"></span>
        <div class="collapse navbar-collapse" id="collapsibleNavbar">
            <ul class="navbar-nav px-2">
                <li class="nav-item px-2 "><a class="nav-link" href="#"></a>Home</a></li>
                <li class="nav-item px-2 "><a class="nav-link" href="#"></a>About Us</a></li>
                <li class="nav-item px-2 "><a class="nav-link" href="#"></a>Our Team</a></li>
                <li class="nav-item px-2 "><a class="nav-link" href="#"></a>Contact Us</a></li>

But isn’t that the purpose of it? That everything inside the collapse container becomes invisible when collapsed?
Can you provide a link to the exercise?

thank you for your reply

you can find the exercise here: https://www.codecademy.com/courses/learn-bootstrap/projects/adhoc-bootstrap

and my github project here: adHoc

what i meant to say was that the links are not displayed in smaller screens

From the Bootstrap docs:

  • Navbars require a wrapping .navbar with .navbar-expand{-sm|-md|-lg|-xl|-xxl} for responsive collapsing and color scheme classes.

So try navbar-expand-sm rather than navbar-expand-md.

If you are using bootstrap 5, try changing the data-toggle and data-target like this (adding bs in between the dashes):

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

The reason is that they changed it on the latest version. Give it a try and let me know.


thanx for your reply

unfortunately that didn’t work

the funny thing is that when i copy paste my code from visual studio to the codecademy editor it works fine. so i reckon it must be sth else maybe sth between the tags

    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
        integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href="..//adhoc/resources/css/style.css">

Try adding Bootstrap’s JS scripts right before the body closing tag. Below all your code.

You can find it here

This one:

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.