Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Developing a responsive navigation bar

From: Up and Running with Bootstrap 3

Video: Developing a responsive navigation bar

Bootstrap does ship with a Navbar that you can use with your webpages. The Navbar comes with many, many options for customization and styling. You can read all about the Navbar here at the getbootstrap.com website. If you go to components and then click on Navbar. You'll find all of the code is here along with various customizations that you can make and tons of styling options. And, I can't possibly go through all of it in one video but I'm going to give you the high points for how to put together a fully responsive Navigational bar inside of Bootstrap in this video.

Developing a responsive navigation bar

Bootstrap does ship with a Navbar that you can use with your webpages. The Navbar comes with many, many options for customization and styling. You can read all about the Navbar here at the getbootstrap.com website. If you go to components and then click on Navbar. You'll find all of the code is here along with various customizations that you can make and tons of styling options. And, I can't possibly go through all of it in one video but I'm going to give you the high points for how to put together a fully responsive Navigational bar inside of Bootstrap in this video.

And then in the next chapter, I'll show you how to attach drop down menus to it, as well. So, what we're going to do is we're going to start with 04_03. Comes from your Exercise Files folder. Copy that from the Exercise folder, and paste it into the Bootstrap folder. And, we're starting here down at row 1 for navigation. So, we're around line 16. The very first thing I'm going to do is change this nav tag that I had associated with the row, back to a div. And that's because I'm going to move the nav tag elsewhere inside of my code.

Where I feel it's a little bit more semantic, which is actually inside of the row tag here. I'm going to add a nav tag right here. And this is going to have a class of both navbar and navbar-default. And we're also going to add a role of navigation. The role attribute that we're adding here is helpful for accessibility purposes. It helps screen readers to know that this is in fact navigation that we're going to add. Then inside of this navtag which I should be sure to close, so I'm going to close that on down here /nav.

And indent my list here. Inside of this nav tag here now in line 18, I am going to add a div with a class of navbar-header. So this is going to be responsible for some bits and pieces of functionality that are responsible for the responsive side of this bar, including the button that you click on in order to get navigation as the screen gets narrower. So I'm going to open that div and I'm going to close it. And then inside of this div with the Navbar of header.

I'm going to include some other things. First of all, I'm going to start with a button with a type of button.Type = button. And a class of navbar-toggle. And then I'm going to add two attributes with which you may not be familiar, data- toggle = collapse. And data-target = #collapse. Alright. So, any time you see data-anything. An attribute inside of HTML 5.

This is an indication of JavaScript working with HTML 5 to make something happen. In this particular case, the toggle indicates that, when this button is clicked, then something is going to happen. In this case, where the data target is specified, and that's #collapse and in a little bit I'm going to be adding a div with an ID of collapse. And, so, what's inside of that div will be affected by the collapse mechanism. So that's what that little bit of code is going to do. Then I'm going to add, after that, a span with a class of sr-only.

Any time you see the class of sr-only inside of Bootstrap. This is for screen readers. That's what that class means, for screen readers only. This is something that you're going to show, and you're going to see these words toggle navigation and /span. That's because the button here that we're going to put in isn't necessarily the most accessible. But this particular span class sr only. If they click this toggle navigation, then that will in fact work. Okay, then we're going to add a span with a class of icon-bar/span.

And we're going to put that in three times. So icon bar, icon bar, icon bar. And then at that point we'll end our button /button. So all of this is inside of the button. So the whole entire unit here is going to become something that's clickable. That's what is going on here inside of this div with a class of navbar header. And as your screen gets narrower and your navigation narrows down to just that button that remains, you click the button to get your navigation. That is what's responsible for the Navbar header here. Then were going to add, after the /div, we're going to add another div.

This is going to be a div with a class of the following: collapse, navbar-collapse and it's also going to have an ID of collapse. And that /div is going to happen here after the /ul. And I'm going to go ahead and indent my list just to make things a little bit easier to read. Okay. So, what's going on here? Well this particular div is controlling our main navigation. So this is the navigation that's going to show on the screen in the bar going horizontally to start with.

And then, as the screen gets smaller, then that navigation is going to disappear or collapse and that's going to turn into the button that we've specified up here at the top. So up here on the top where we have this data target of #collapse, that goes with the ID down here of collapse. In other words, what we've said is when this button is clicked. When it's present and it's showing on the screen at these lower resolutions and we click that button. Then whatever is inside of this div will become visible.That is what we're talking about.

And we've tied those two things together between this idea of collapse. And our data target of #collapse. You don't have to use an ID here. You could have used a class just as easily, and tied the class to our data target up here. If you did a class, it would start with a period instead of with a pound sign. Then the last thing we need to do here is on this UL where we had a class of nav, nav pills, nav justified. Well that's not what it is anymore. We're going to leave the nav, but we're going to change it to navbar-nav. And once you have those things in place go ahead and save your webpage.

And we can put this inside of our browser. And lo and behold. We have a Navbar going across the top of our page. How cool is that? And we're on the Services page. Because that's designated our active page. And we can scroll on down the page. And things are good. And we can make this page smaller, and as I make this page smaller and smaller, finally we wind up with the button here up on the top. And this button has been called many things, this button with three bars, and I've started to collect names. So some of my favorites are the Hamburger button.

The Pancake button. Or the Adidas button. When you click that button, this is the navigation that you get that appears here on the page. Alright. So by default, the Navbar that you get is this sort of pale, sort of whitish color and it doesn't stretch the full width of the page. So something that you might want to do is change the color of this Navigation bar and/or make it stretch the whole width of the page. So there's some additional classes that allow for that. So, one of the things that we can add then here to our nav tag on line 17. We're going to add navbar-inverse.

And that will change the color of the bar from whitish to, of course, a very, very dark grey, almost black. So if you refresh your webpage, you'll now see that we have a black bar instead, which I think is a little bit more attractive. And one other thing that we can do, is we can make this Navigation bar stretch fully across the screen. No matter what width it is. And fixed to the top of the screen. So that as we scroll down, the Navbar on the top will stay in place. We actually see that in place here in the Bootstrap top Navigation bar. You'll see that that stretches all the way across the page.

And as I scroll down that top Navigation is always there and present. And, of course, this will turn into its little button here, as the screen gets smaller. So, in order to make that happen, here in this navtab also, again on line 17 we're going to add a class of navbar-fixed-top. And that's going to fix the navbar to the top of the screen. So if you save that and you refresh your webpage, there we go, now our Navbar is stretching all the way across the screen, no matter how wide we make it.

But notice the other little problem that happened here. The heads of our animals all got cut off. And it will tell you in the Bootstrap documentation that this will happen when you use the navbar fix to the top. And it actually gives you the fix as well, which is a quick little style that we need to add. So if you open up your custom.css. And up here, I'm just going to put it as the very first style in my style sheet here, on line 2. We're going to add a style for body, and we're going to tell it to give it a padding-top of 70 pixels.

Save that, and refresh your web page. And now, your heads of your dogs are no longer cut off. The Navbar is fixed up here on the top of the screen. As you make your screen narrower, it does, in fact, collapse down to the button here. Which will still open and show you all of your navigation. So, that is Bootstrap's Responsive Navigation bar in a nutshell.

Show transcript

This video is part of

Image for Up and Running with Bootstrap 3
Up and Running with Bootstrap 3

37 video lessons · 24995 viewers

Jen Kramer
Author

 
Expand all | Collapse all
  1. 5m 25s
    1. Welcome
      58s
    2. Using the exercise files
      1m 19s
    3. Installing Sublime Text 2
      3m 8s
  2. 29m 0s
    1. What is Bootstrap?
      8m 1s
    2. Downloading and unzipping Bootstrap 3
      4m 31s
    3. Examining Bootstrap file structure
      4m 34s
    4. Adding CSS to a Bootstrap HTML file
      4m 35s
    5. Adding JavaScript to a Bootstrap HTML file
      7m 19s
  3. 44m 38s
    1. Exploring Bootstrap's grid system
      9m 10s
    2. Creating new rows and cells
      14m 5s
    3. Adjusting column widths using offset
      5m 2s
    4. Changing column order using push and pull
      5m 34s
    5. Nesting columns
      3m 43s
    6. Creating a JumboTron-style layout
      3m 41s
    7. Challenge: Working with grids
      1m 31s
    8. Solution: Working with grids
      1m 52s
  4. 53m 34s
    1. Exploring basic typography: The small and blockquote tags
      4m 29s
    2. Exploring Bootstrap's responsive classes including .hidden and .visible
      4m 44s
    3. Styling buttons using btn classes
      4m 43s
    4. Styling images with responsiveness and decorative touches
      5m 22s
    5. Incorporating Bootstrap 3 glyph icons
      3m 28s
    6. Creating a thumbnail gallery
      6m 2s
    7. Styling tabular data
      5m 3s
    8. Overriding core CSS with custom styles
      12m 53s
    9. Challenge: Styling panels and callouts
      2m 17s
    10. Solution: Styling panels and callouts
      4m 33s
  5. 27m 41s
    1. Implementing location breadcrumbs
      6m 38s
    2. Using tabs and pills for navigation
      6m 58s
    3. Developing a responsive navigation bar
      9m 9s
    4. Challenge: Modify the "pancake" button
      1m 3s
    5. Solution: Modify the "pancake" button
      3m 53s
  6. 37m 45s
    1. Implementing dropdowns within a navigation bar
      5m 5s
    2. Tabbing within the same page
      15m 45s
    3. Accordion panels with collapse functionality
      11m 37s
    4. Challenge: Tooltips
      1m 59s
    5. Solution: Tooltips
      3m 19s
  7. 3m 0s
    1. Next steps towards advanced Bootstrap
      3m 0s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Up and Running with Bootstrap 3.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.