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 trialLuka Sarich
13,204 PointsSame code block, won't run on a different HTML file?
Hi, I am working on building a personal website utilizing Bootstrap. I've used their 'Navbar Collapse Toggle', and it works flawlessly on the first three .html files (I've just copied and pasted the same HTML to each file, however, the navbar toggle doesn't want to open on my last page. This is the code chunk that is copy and pasted to each file.
<!-- NavBar Image and text -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark sticky-top">
<a href="/Users/lukasarich/Desktop/Main Website/index.html"><img src="/Users/lukasarich/Desktop/Main Website/Images/logo_transparent.png" width="115" height="32" class="" alt="Website Name"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo02">
<ul class="navbar-nav ml-auto mt-2 text-center">
<li class="nav-item pb-2">
<a class="nav-link" href="/Users/lukasarich/Desktop/Main Website/benefits.html">Benefits</a>
</li>
<li class="nav-item pb-2">
<a class="nav-link" href="/Users/lukasarich/Desktop/Main Website/whyus.html">Why Us</a>
</li>
<li class="nav-item pb-2">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</nav>
<!-- End NavBar -->
1 Answer
Shaun Kelly
35,560 PointsHi Luka,
Looking at the code, you don't have a href attribute set for the last list item.
So i presume what you're after is....
<!-- NavBar Image and text -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark sticky-top">
<a href="/Users/lukasarich/Desktop/Main Website/index.html"><img src="/Users/lukasarich/Desktop/Main Website/Images/logo_transparent.png" width="115" height="32" class="" alt="Website Name"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo02">
<ul class="navbar-nav ml-auto mt-2 text-center">
<li class="nav-item pb-2">
<a class="nav-link" href="/Users/lukasarich/Desktop/Main Website/benefits.html">Benefits</a>
</li>
<li class="nav-item pb-2">
<a class="nav-link" href="/Users/lukasarich/Desktop/Main Website/whyus.html">Why Us</a>
</li>
<li class="nav-item pb-2">
<a class="nav-link" href="/Users/lukasarich/Desktop/Main Website/contact.html">Contact</a>
</li>
</ul>
</div>
</nav>
<!-- End NavBar -->
Hope this helps,
Shaun