Up and Running with Bootstrap 3
Illustration by John Hersey

Implementing dropdowns within a navigation bar


From:

Up and Running with Bootstrap 3

with Jen Kramer

Video: Implementing dropdowns within a navigation bar

Now that we've got that nav bar in place and it's looking great, one of the next things people ask about at this point is how to add a drop-down to the navigation bar. And Bootstrap has a number of way of adding drop-downs to in fact a number of elements within a Bootstrap-powered web page. I am looking at getbootstrap.com. If you go to the component section of the documentation, and click on Dropdowns, you can read all about the dropdowns here and how they work. This is just dropdowns in general. Note also that over here in the left navigation, there's the option of button-based dropdowns.
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. 43m 46s
    1. Exploring Bootstrap's grid system
      9m 10s
    2. Creating new rows and cells
      13m 17s
    3. Adjusting column widths using offset
      5m 2s
    4. Changing column order using push and pull
      5m 33s
    5. Nesting columns
      3m 42s
    6. Creating a JumboTron-style layout
      3m 40s
    7. Challenge: Working with grids
      1m 30s
    8. Solution: Working with grids
      1m 52s
  4. 53m 33s
    1. Exploring basic typography: The small and blockquote tags
      4m 28s
    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 40s
    1. Implementing location breadcrumbs
      6m 37s
    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 your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now
please wait ...
Watch the Online Video Course Up and Running with Bootstrap 3
3h 21m Beginner Oct 07, 2013

Viewers: in countries Watching now:

Meet Bootstrap, the one-stop shop for designing sleek, mobile-ready websites with HTML5, CSS3, and JavaScript. It's an open-source, responsive design framework, featuring a grid-based layout system, web-ready icons you can incorporate into your designs, fully functional navigation, and much more. Join Jen Kramer for a quick overview of all of the goodies in Bootstrap, and then learn how to customize the grid, override the CSS to customize your site, and leverage Bootstrap's stylish built-in JavaScript effects. Once you're prepared to test your knowledge, you can take the hands-on challenges offered by Jen.

Topics include:
  • Downloading and installing Bootstrap
  • Understanding the Bootstrap file structure
  • Exploring the 12-column grid
  • Changing column width and order
  • Styling buttons, images, and tables
  • Overriding core CSS
  • Creating a thumbnail gallery
  • Adding JavaScript effects, like dropdown menus, tabs, accordions, and more
Subject:
Web
Software:
Bootstrap
Author:
Jen Kramer

Implementing dropdowns within a navigation bar

Now that we've got that nav bar in place and it's looking great, one of the next things people ask about at this point is how to add a drop-down to the navigation bar. And Bootstrap has a number of way of adding drop-downs to in fact a number of elements within a Bootstrap-powered web page. I am looking at getbootstrap.com. If you go to the component section of the documentation, and click on Dropdowns, you can read all about the dropdowns here and how they work. This is just dropdowns in general. Note also that over here in the left navigation, there's the option of button-based dropdowns.

I'm not going to cover these in this tutorial, but it is possible to add these dropdowns to individual buttons as well. So you can tie these dropdowns then to that navigation bar, you can tie them to pills or tabs or you can tie it to the responsive navigation bar and that's what I'm going to show you how to do in this video. So if you go to your Exercise Files folder and go to folder number 05_01, you'll find this HTML file. Copy this file from your Exercise Files folder over into your Bootstrap folder.

And open it up here in sublime text. If you right click anywhere on the page and say, Open in Browser, you'll see how this page currently looks. And, so there is that top navigation bar that we added before. And, you'll see that something else has been added here. And that is these names of the doctors here. They're actually under the about menu item. And, in fact this is still a responsive navigation bar. We still have our menu showing up here and it kind of, sort of looks okay at the smaller resolutions. But it doesn't really look particularly good like this just yet.

So if you take a look at the HTML that I've given you and we're down around lines 28 or so. This is just an ordered list for the main navigation bar and then you'll see that we have embedded in that another unordered list. One of the important points to remember with unordered lists is that if you're going to nest them in the way I've nested them here, is that this unordered list should go inside of the list item, the parent list item. Very, very important. I find that a lot of beginners to HTML forget this. They close their li and then they just insert the ul.

Really inside of the other ul and that's actually not correct. So, what we're going to do to make this work, then, as a dropdown, is we're just going to add some additional classes here, and then, this is just going to work as a dropdown. So, here on the li, here on line 28. This is the containing li for the document. Were going to add a class of dropdown, and then were going to add here on the ul, the embedded ul, we're going to add a class of dropdown hyphen menu.

And this is going to drive a lot of the styling that's involved here. Another little piece that's involved with the styling is something we'll add right here after the word about, but before the slash a. I'm going to add the span tag with a class of caret. CARET. And what that will do is it will put the little triangle next to the word About, indicating that there's a dropdown menu there. You don't have to put it in this span with a class of carat. Or you could swap it out for some other sort of icon, if you wish.

It's a helpful user interface addition to have the little carat in place, because it will indicate that this particular menu item has a dropdown associated with it. And then the very last thing that you have to do in order to make this whole thing work is inside of the ref. Associated with the li that's the parent of this dropdown menu and we're going to add data hyphen toggle equals dropdown. So data hyphen anything in HTML5 is an attribute that indicates this has something to do with JavaScript.

So, this is what we're using to bind the JavaScript that's going to drive this dropdown to this particular li. So that we click on the li, the dropdown is going to appear and that is what this data toggle attribute is doing. You can customize these data hyphen attributes with anything. It happens to be that Bootstrap is called this data hyphen toggle but if you're writing JavaScript, you can write your own attributes that will go in a data hyphen type of attribute and interestingly data hyphen anything will validate with HTML 5, it's very important to know.

OK, so let's go ahead and save this page, File Save, and if you right-click anywhere or Cmd+click anywhere on the page and say Open in Browser, you will have the revised page displaying here inside of your browser Window, and you will see that the word about over here now has a little triangle next to it. That's driven by that span with the class of carat. If you click on the word About, you'll have your dropdown menu here. Now, it's worth noting of course, that Bootstrap's dropdowns are driven by clicks and not by hovers. And why is that? Well remember that this has to work on mobile devices as well as on desktops.

So, you can't really hover on anything on a mobile device. Your users are going to have to click on the particular item in order to find the dropdown to work with Bootstrap's dropdowns right out of the box.

Find answers to the most frequently asked questions about Up and Running with Bootstrap 3 .


Expand all | Collapse all
please wait ...
Q: I don't see the respond.min.js file at the URL mentioned in the Chapter 1 movie "Adding JavaScript to a Bootstrap HTML file" (https://github.com/scottjehl/Respond). How do I access the file?
A: It appears the respond.js author updated the code or rearranged the file structure. You can find respond.min.js at this URL: https://github.com/scottjehl/Respond/tree/master/dest.
 
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.

* Estimated file size

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 ?

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.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

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.