Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an ordered List with Twitter Bootstrap Component?

I have a simple ordered list, super easy:

http://www.bootply.com/P8wglPiSVD

Looks like this:

<div class="container">
    <div class="row">
        <div class="col-xs-12">
            <ol class="list-group">
                <li class="list-group-item">
                    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vitae, aliquid.</p>
                </li>
                <li class="list-group-item">
                    <p>Quos nostrum provident ex quisquam aliquid, hic odio repellendus atque.</p>
                </li>
                <li class="list-group-item">
                    <p>Facilis, id dolorum distinctio, harum accusantium atque explicabo quidem consectetur.</p>
                </li>
            </ol>
        </div>
    </div>
</div>

But twitter bootstrap isn't showing any numbers, even though it is an ordered list.

I searched but didn't find any twitter bootstrap compontent that styles ordered list items and this makes me curious. Is there a lacking in a predefined style for Twitter Bootstrap for ordered lists or am I missing something?

Kind regards,

George

like image 794
LoveAndHappiness Avatar asked Jun 15 '14 15:06

LoveAndHappiness


People also ask

How do I create an inline list in bootstrap?

Placing Ordered and Unordered List Items Inline. If you want to create a horizontal menu using the ordered or unordered list you need to place all list items in a single line (i.e. side by side). You can do this simply by adding the class . list-inline to the <ul> or <ol> , and the class .

How do I create a list group with linked items in bootstrap?

List Group With Linked Items: Use <div> and <a> tag instead of <ul> and <li> to create a list of group with linked items. The . list-group-item-action class is used to set the hover effect to change the background color to gray.

How do I create an ordered list in a list?

To create ordered list in HTML, use the <ol> tag. Ordered list starts with the <ol> tag. The list item starts with the <li> tag and will be marked as numbers, lowercase letters uppercase letters, roman letters, etc. The default numbers for list items.

Can you enumerate the various lists supported by bootstrap?

The most basic list group is an unordered list with list items: First item. Second item. Third item.


4 Answers

Combining @Steve Sanders and @beiping_troop answers, you can create clean ordered list-groups with the following CSS:

.list-group {
    list-style: decimal inside;
}

.list-group-item {
    display: list-item;
}

http://www.bootply.com/BJadu6Ja6R

like image 102
inostia Avatar answered Oct 12 '22 02:10

inostia


Bootstrap is applying display: block to the list items, which kills the numbering. Add this to your CSS:

.list-group-item {
    display: list-item;
}

http://www.bootply.com/ZHQBWK9sHB

like image 35
Steve Sanders Avatar answered Oct 12 '22 02:10

Steve Sanders


For just a clean ordered list, I chose an inline style override since I was only calling out a numbered list in one place. It rendered just fine:

<ol style="list-style: decimal inside;">
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>

My reference was originally here: Bootstrap: numbers from ordered list disapear when using media object

like image 38
beiping_troop Avatar answered Oct 12 '22 02:10

beiping_troop


I found a better solution is to add a new css class to the list group depending on the style of numbering you want for example "list-group-numbered" or "list-group-alpha" that way you can add the numbering to only the ordered lists you want to add it to and not to all numbered lists, especially if you have somewhere else on the website that has numbered lists that now looks wrong...

.list-group-numbered { list-style: decimal inside; }
.list-group-alpha { list-style: lower-alpha inside; }
.list-group-roman { list-style: lower-roman inside; }
.list-group-alpha >li, .list-group-numbered >li { display: list-item }

then you can put in the following in html..

<ol class="list-group list-group-numbered">
    <li class="list-group-item">an item
        <ol class="list-group list-group-alpha">
            <li class="list-group-item">a sub item
                <ol class="list-group list-group-roman">
                    <li class="list-group-item">a sub-sub item</li>
                </ol>                
            </li>
        </ol>
    </li>
    <li class="list-group-item">another item</li>        
    <li class="list-group-item">a third item</li>
</ol>
like image 41
TheKLF99 Avatar answered Oct 12 '22 02:10

TheKLF99