Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Why isn't my navbar collapse working with Bootstrap?

I am confused to why my bootstrap collapse isn't working. Ever since I wrapped the nav with this collapse div no links show:

<nav class="navbar navbar-default affix-top nav-links" data-spy="affix" data-offset-top="100" role="navigation">
    <div class="container">
        <div class="navbar-header"> 
            <a class="navbar-brand" href="/"><img src="media/img/nav-logo.png" alt="Driven Car Sales Logo" class="img-rounded logo-nav navbar-brand"></a>
        </div>
          <div class="nav-collapse collapse navbar-responsive-collapse">
            <ul class="nav navbar-nav">
                <li><a href="#">Used Cars</a>
                </li>
                <li><a href="#">Get Finance</a>
                </li>
                <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">About Driven<strong class="caret"></strong></a>
                 <ul class="dropdown-menu">
                  <li>
                   <a href"#">The Team</a>
                  </li>
                  <li>
                   <a href"#">Our Partners</a>
                  </li>
                 </ul> <!--Drop Down End-->
                </li>
                <li><a href="#">How To Find Us</a>
                </li>
                <li><a href="#">Contact Us</a>
                </li>
            </ul>
          </div>    
    </div>
</nav>

Here is the CSS I am using:

.logo-nav {
    height: 2.3em;
    width: auto;
}
.brand {
    font-size: 2em;
    margin: 20px 0 25px;
}
.navbar-brand {
    opacity: 0;
    color: #ff0066;
    -webkit-transition:opacity 0.3s ease-in;
    -moz-transition:opacity 0.3s ease-in;
    -o-transition:opacity 0.3s ease-in;
    transition: opacity 0.3s ease-in;

    margin-left: 0px;
}
.navbar {
    border-radius: 0px;
    border-left: none;
    border-right: none;
}

.navbar-default .navbar-nav>.open>a, .navbar-default .navbar-nav>.open>a:hover, .navbar-default .navbar-nav>.open>a:focus {
    color: #fff;
    background-color: #DD3B4D;
}

.navbar-default .navbar-nav>li>a:hover, .navbar-default .navbar-nav>li>a:focus {
    color: #fff;
}

.dropdown-menu {
    color: #fff;
    background-color: #DD3B4D;
}

.dropdown-menu>li>a {
    color: #fff;
}

nav.affix {
    top: 0;
    width: 100%;
    z-index: 1000;
}
nav.affix .navbar-brand {
    opacity: 1;
    height: 2.3em;
    width: auto;
}

.navbar-header {
    width: 0px;
    -webkit-transition:width .4s ease-in-out;
    -moz-transition:width .4s ease-in-out;
    -o-transition:width .4s ease-in-out;
    transition:width .4s ease-in-out;
    margin: 0 1em 0 1em
}

nav.affix .navbar-header {
    width: 8em;
    -webkit-transition: width .4s ease-in-out;
    -moz-transition: width .4s ease-in-out;
    -o-transition: width .4s ease-in-out;
    transition: width .4s ease-in-out;
    margin: 0 1em 0 0;
}

.nav-links {
    font: 600 15px/1.5 'Arimo';
}

.navbar-nav > li:last-child{
    border-right: 1px solid #475d88;
}

ul.nav a:hover { 
    color: #fff !important;
    background-color: #DD3B4D !important;
    -webkit-transition: background-color 0.6s ease;
    -moz-transition: background-color 0.6s ease;
    -o-transition: background-color 0.6s ease;
    transition: background-color 0.6s ease;
}

nav.affix .navbar-brand { 
    display: inline-block; 
}

Any idea why it just hides the links in a large viewport?

Here is a live version: http://www.dealerbyte.co.uk

Thanks guys any help would be much appreciated :)

Are you including all the correct CSS and JS link above and within the body tag?

Yes as far as I am aware, all the other bootstrap components wouldn't work if I hadn't linked them properly would they?

True, but the only time I have had trouble with jQuery / JS functionality not working is because I am not linking correctly. The collapsing navbar, that becomes an icon in particular. You have the latest jQuery.min.js linked at the bottom of body? Either by CDN or as a file in your directory.

1 Answer

Bring up your browser's developer tools and see if there are any errors or warnings. That may lead to an answer.

Good call.