Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Well, we've been working away on Bootstrap here and we've gone through several chapters of building individual webpages. But did anyone notice that there was something missing that was kind of obvious? Like I don't know, a navigation bar. We built all these great pages for this website but they have no way of linking to each other. So it's high time that we talked about navigation bars and how we could actually link together all these pages into a coherent website. So I am taking a look at file 04_02, which comes from your exercise files folder. Go ahead and copy this file into your Bootstrap folder.
And then open it on up in your browser, and you should see this. And so what you see here, is, I've got two navigation items going on here. Up at the very top left of the page above the logo. I have a bulleted list. Ultimately of course that should probably become some kind of horizontally oriented navigation for this website. And then underneath the logo I have another set of navigation. This is probably some kind of sub navigation for this particular part of the website. And, this might lead to other pages, or it could lead to other sections on the same page.
So, I need to style both of these things, because they really don't look all that great just as they are, and so, I would like to walk through that now. And so we've got two bars that we need to style. So, I'm going to start by going to Sublime Text, here, and I'm going to show you the mark up that I've used to put these navigation bars in place. So, starting here, now, around line 16, is the top navigation bar for the website. And I've marked this up with a nav with a class of row. So the nav tab once again one of the HTML five semantic tags indicating that this is a major piece of navigation on the website.
And here's an un-ordered list because ultimately, it really doesn't matter what order these links are in. It matters to marketing of course, but one page isn't related to the other. In the case of the breadcrumb, we needed to mark this up as an ordered list because it does very much matter that the order that those links are in. And then, further on down the page here, if we go down to line 92. This is it on the side here. This is our sub navigation for the website. And notice that this is not in a navigation tab.
Why would I not put this in a navigation tab? Because the specs for the navtab indicates they should go in place where there is major navigation for the website. Where, if this were missing, it would really be a kind of tragedy, it couldn't navigate the website. So my determination was that this was not major navigation for the website, so I did not use a navtab in this particular place. If you feel this is major navigation for your website, by all means you can certainly go ahead and use that nav tag. These symantic questions aren't not necessarily all that cut and dry.
So, that is why there's no nav tag here. So, what we're going to do to start with, just to get a very basic nav bar. Is we're going to add a class. And that class is right here on this ul. We'll add a class of nav. This is on line 93. And we'll also add that class of nav all the way up here on line 17. Class of nav. And if you just go ahead and save your page and refresh it here in you browser. You'll see that, already, something has happened.
And, in fact, these are styled exactly the same way. Sort of a block level kind of navigation. When you hover over it, you get this grey bar, that is as wide as its containing element. That's very very wide up here on the top. And not as wide down here in the left column. So that is the most basic navigation bar. Just adding that class of nav to the ul. Then, we can continue to add classes here in order to get additional styling. So, back here on line 17 I can add a class of nav, hyphen, tabs.
So this is going to orient things as tabs on the page. In order to make this work. To have tabs that really look like tabs. I need to also indicate what page I'm currently on. Well, I'm on the services page. So, to the li, I will add a class of active. Indicating, that this is where I am in the hierarchy. So, if you go ahead and save this and if you refresh this in your browser, you'll see that we now have a tab, for the page that we are currently on, which is services. If this other navigation was working, which it's not hooked up to anything, so it doesn't, as we switch to other pages here on the site, then the active state should move and that would change the shape of this tab, to fit other places here on the page.
You can add, nav of tabs, down here. On line 93 you could add a nav hyphen tabs here also. That off course is going to make your navigation go horizontally across the page. But if you add a nav hyphen stacked, this is going to stack your navigation and keep it vertical, even though you are calling for tabs. So, if you save this, and you take a look at this inside of your browser. These are now considered to be tabs and because I didn't specify which one was active, these don't really look all that tabby.
So, let me indicate which one is an active one. So class equals active here on this li. And now, if I refresh the page, then I do have a tab here, which indicates the Vaccinations is active. Although I can navigate to these other pages. I don't think the tabs in a stacked format works really well, but it's supported. And you can certainly set things up this way. What actually works better in this orientation is the pill format. Here again on line 93, if you change nav tabs to nav pills, pills, and save and refresh your webpage you'll see that now we have these lovely pills over here on the left side of the screen.
With the active page indicated by the big blue pill. And of course you probably want to change the colors here at some point in time to make this work better with the color scheme for your website. Likewise we can add a class of pills up here at the top of the page. So scrollall the way back on up. Up here to the top on line 17. Instead of nav tabs we can change this to nav pills. Save that. And refresh our web page. And now I have these lovely pills that grow across the top of the page. And as my very final trick, you might want to stretch this navigation out to stretch the full width of the page.
And that's completely possible now with Bootstrap 3. You're going to add to nav pills. Nav-justified. And that will justify the navigation across its containing element, which in this case it's 12 columns wide. So, it's going to go all the way across. So, there we go. Now, we have navigation that stretches fully across the page. Designers might not be happy. It looks like the word home here isn't quite aligned with things, but when you mouse over it you'll see that if the left edge of that pill is in fact aligned with the left column there. So, just with a handful of classes, including nav, nav tabs, nav pills, nav justified.
And now stacked so those five classes and various combinations, we're able to change the look of these navigation bars here on our website in just a few clicks.
Get unlimited access to all courses for just $25/month.Become a member
58 Video lessons · 65592 Viewers
61 Video lessons · 96371 Viewers
56 Video lessons · 110115 Viewers
82 Video lessons · 105070 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.