Start learning with our library of video tutorials taught by experts. Get started

Up and Running with Bootstrap 2

Creating a photo carousel


From:

Up and Running with Bootstrap 2

with Jen Kramer

Video: Creating a photo carousel

The last JavaScript effect I am going to show you is the Image Carousel, and this is so cool. People love these carousel kind of effects. You see it in action right here on this web page. Here we've got a series of photos that are scrolling on by with some text underneath. We have little buttons here so that I can click to the next image as fast or as slow as I want. I can go backwards. These carousels are pretty much everywhere on the web these days, and there's a thousand different ways to code them. Well, we're going to learn the Bootstrap way of doing it.

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
Please wait...
Up and Running with Bootstrap 2
2h 38m Beginner Oct 12, 2012

Viewers: in countries Watching now:

Bootstrap is a free web development tool from Twitter that, with a little bit of CSS and JavaScript experience, makes building websites quick, intuitive, and fun. Author Jen Kramer explores its 12-column grid layout; typography and icon libraries; fully functional components like nav bars, buttons, and tabs; and much more. This course also shows how to add JavaScript extras like dropdown menus, modal windows, and photo carousels.

Topics include:
  • Understanding the difference between default and fluid grids
  • Nesting with fluid grids
  • Creating a thumbnail gallery
  • Adding block quotes and lists of text
  • Incorporating images and icons
  • Adding breadcrumb navigation and pagination
  • Using tabs and pills navigation
  • Making the nav bar responsive with JavaScript
  • Adding dropdown menus to the nav bar, tabs, and pill
Subjects:
Web CMS Blogs Responsive Design Web Design
Software:
Bootstrap
Author:
Jen Kramer

Creating a photo carousel

The last JavaScript effect I am going to show you is the Image Carousel, and this is so cool. People love these carousel kind of effects. You see it in action right here on this web page. Here we've got a series of photos that are scrolling on by with some text underneath. We have little buttons here so that I can click to the next image as fast or as slow as I want. I can go backwards. These carousels are pretty much everywhere on the web these days, and there's a thousand different ways to code them. Well, we're going to learn the Bootstrap way of doing it.

So if you take a look at your starting Carousel document, you will notice that we have some photos here. They have a little bit of text that go underneath of all of these. There is down here at the bottom some tiny little left and right arrows, and if we take a look at this in Dreamweaver, you'll see that that code is exactly the same. We have some images, we have some headings with little bit of text underneath, and then down here at the bottom we have little left and right arrows. Now what we need do is mark this up to make it all work for the carousel.

So first of all, the easiest thing to add are some divs here which will designate where the captions for this carousel are going to be. So just after the image, before the h4, we are going to add a div with a class of carousel-caption. And then of course, after the last closing paragraph, make sure you close the div. And I am going to do that three times here, div with a class of carousel-caption, and one more time, div class carousel-caption, /div. Okay.

So we have marked off where those carousel captions are going to appear, now we have basically a unit that occurs here, the image plus the carousel caption, that is all a grouping itself. So I am going to add another div for that, this is a div with a class of item, and I am putting a little bit of spacing between each one of these groupings just to make things a little bit easier to read, div class item, one more up here on the top.

You will notice that once again, as I have done with many of the other videos in this title, I am not using the grid system here for displaying this carousel. Of course, you could take the code that I am going to put here in between the body tags, you could copy that into one of the columns inside of your grid to display on your website. That's a very simple thing to do. The other thing I want to add here for the very first item is I want to designate this as an active item. In other words, I want the carousel to start with the first one.

So I am going to designate it as such. Now I need to add just two more divs. I am going to wrap everything that you see here in another div with a class of carousel-inner, scroll all the way down to the bottom, and we are going to close that tag just before the href down here in the bottom of the screen. Then just above that div with a class of carousel-inner, as you might expect since it was called inner, we have to have an outer one, right? So I am going to add one final div here to the mix.

This will be div with a class of carousel. And then I am going to close that all the way down here just after the hrefs down here in the bottom, which will be that little arrow either way. Okay, in that div with a class of carousel, also give it a class of slide. This will cause the images to have that wonderful sliding effect from one to the next. Without the class of slide, what will happen is they will simply appear one after the other.

And I am also going to give this an ID of artists. All right! So that's all the markup that we need for the actual content of the carousel. Now we are going to scroll on down to the bottom of the page where we have these links with the left and right arrows, and we are going to apply some additional classes and information down here. So for our left quote, let's go ahead and apply some styling to this. We give it a class of left as well as carousel-control.

As you would expect, that's going to apply to the left arrow, make it go to the left side of the images, and likewise for the next arrow, let's go ahead and give that a class of right carousel-control. Instead of the href of just Pound here, we are going to give this an href of #artists. Just as we have seen before, the ID above needs to match the href so that the JavaScript can work correctly.

And last of all is the action here that we have to have on this href, and in this case it's data-slide, and that will be previous, P-R-E-V ,for the first one and data-slide="next" for the last one. All right! So now that we have got all that information packed into these a tags down here at the bottom of the screen, we are ready to save our document. So Ctrl+S or Command+S to save the document.

Go on down here to Firefox and refresh your page, and you should see a fully formatted carousel. It does stretch all the way across the page, that's because, of course, the containing element for this particular page is the body tag. I don't have the scaffolding in place to make this carousel smaller or larger. If I click my arrows here, you can see that the images jump in between just fine. Isn't that great? And of course, we have the text underneath, describing each one of our images.

So the image carousel is a great way to show off photos on your website, add a little bit of sizzle and interactivity, and they are very fun and interactive.

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


Expand all | Collapse all
Please wait...
Q: I am trying to create the image carousels shown in this course, and they are not functioning properly. The custom.css file seems to be missing from the exercise files and I think this is the reason. Can you provide it?
A: custom.css isn't created until the carousel indicators are added. However, these styles have to do with the way the indicators look, and nothinghas to do with the way the carousel functions.
 
Are you sure you're working with Bootstrap 2.x? You download that from here: 
http://getbootstrap.com/2.3.2/. The carousel changed radically between Bootstrap 2.x and Bootstrap 3, and this course might not work with version 3.
Share a link to this course
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.
Upgrade now


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.

Upgrade now

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 2.

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 preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Welcome to the redesigned course page.

We’ve moved some things around, and now you can



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.

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.