Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom numbered lists with css

Tags:

html

css

Is there a way to control the text used for the numbering?

For example, is there a way to have the list automatically do something like this:

First,     blah-blah
Second,    blah-blah
Third,     blah-blah
Fourth,    blah-blah
etc.

1 Answers

Check this fiddle: http://jsfiddle.net/yR6G6/

What we are doing here is adding a pseudo :before element to each LI and customizing its content with JavaScript.

NOTE: This solution assumes you are ok using JS and jQuery. A pure CSS solution is likely not possible at all.


HTML

<ul>
    <li>Item</li>
    <li>Item</li>
    <li>Item</li>
</ul>

CSS

ul li:before {
    content: attr(data-label);
    color: red;
    text-align: right;
    padding-right: 10px;
    font-size: 11px;
    width: 60px;
    display: inline-block;
}

JS

var labels = [
    "First",
    "Second",
    "Third"
    // and so on...    
];

$('ul li').each(function(i) {
    $(this).attr('data-label', labels[i]);
});
like image 179
techfoobar Avatar answered Aug 06 '26 21:08

techfoobar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!