- View Offline
Those groups are a new type of component that lets you create mobile-like lists with a lot of different options. You see the markup is pretty simple. You can create a list by using an unordered list, the class of list-group, and then a list item with list-group-item classes. And you can add chevrons pretty easily, as well as badges, to the right, and also make these into clickable components by making them into anchor tags. So let's take a look how that works. So starting off with the file from the movie Working With Panels. And the first thing we're going to do is just create a list, so we'll go ahead and remove this content right here and I'm going to give plenty of spacing. And I'll create a list, list will have a class of list group. And we're, we'll go ahead and add some list items and the list items will have a class of list-group-item.
Go in and make about five of those. Alright, so inside each one of these I'm going to type in just some text. So I'll just do first and so on and so forth. And I'll save that, and I'll refresh this page. Looks like I missed a hyphen here, so let me go ahead and fix that. I'll just add a hyphen, and refresh the page, and it should look like this. It just looks like a series of mobile device list elements. That's pretty cool. Notice that there's a little bit of padding around the list, and if you want that that's cool.
You can also add another class that is unordered list to make those flush, so I'll add a list-group-flush class there. And you can see that everything kind of goes up to the edge. So either way, whichever way you want to style them, that's great. Now let's go ahead and add some chevrons and then maybe some badges. They're pretty easy to do and it actually doesn't matter where you put them, so If I can do a span, with a class of glyphicon, and then I add another class of glyphicon, and then chevron-right, and I save that.
I get a chevron right here to the right hand side, which is pretty cool. I can also add a badge pretty easily, I'll just create a span with a class of badge, and then I can put a number in here, so I'll put the number ten and save that, and refresh. You can see the badge appears. Notice that the order does matter a little bit. I want to do the chevrons first and then the badge next, but it doesn't matter that I have the content before or after. It's just placing these where they need to go on the right-hand side. So that's actually pretty cool. Now if I want to get more complicated with my content, I can also define some sort of heading.
So I'll do an h4 with a class of list-group-item-heading, and let me put this content here inside. So I'll paste that, and then I'm just going to put some text here. So I'll put some long text and I'll save this and you can see that it aligned pretty well. I really do want to put in another class inside my text called list-group-item-text, and I know this is getting a little bit wordy but it really pays off to use these classes. It knows how to align things properly if you use them. So you can also make these into clickable elements by adding some anchor tags. And as a matter of fact, what I'm going to do is, I'll take the on order list here and change it to a div, and I'm going to take my list items and change them to anchor tags.
So I'm going to select this one, and I'm using sublime text here so you can do Cmd+D, Cmd+D, Cmd+D to get all the other ones. And then hit the right arrow and make a selection, and I'll change that to an anchor tag right here. Now because this is an anchor tag, I need to do an href, of, I'll just do #, because we don't really need to, link them to anywhere, we just need to show how they work. And then I need to find all the closing list items. This one's right here; select that one, Cmd+D a few times and then hit the right arrow. I have multiple cursors, and I can close all my anchor tags at the same time.
Save, and refresh, and now, you can see that these actually highlight. It's showing me the little hand icon, and these are actually clickable, and it made sure that it styled everything correctly when I did that, which is pretty awesome. You can also add a class of active to any element that you want to highlight as being an active link, and that's pretty cool. These additions to Bootstrap are very mobile-focused, but they give you a lot of power without having to do a lot of CSS. So I really like this addition to the Bootstrap framework.
- Installing Bootstrap 3
- Using the new grid systems
- Working with typography
- Understanding the responsive class updates
- Using panels and list groups
- Migrating from Bootstrap 2.3 to Bootstrap 3.0