开发者

custom numbered lists with css

开发者 https://www.devze.com 2023-03-26 02:59 出处:网络
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:

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,开发者_StackOverflow社区     blah-blah
Fourth,    blah-blah
etc.


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]);
});


If I understand you correctly, you want to only indent the second line. You could do something like this:

li {
    text-indent: -1em;
    padding-left: 1em;  
}

You'll need to play around with those values, and with the values for the <ul> or <ol> element to get everything right.


ul {
    list-style-position: outside;
}

http://www.w3schools.com/cssref/pr_list-style-position.asp

This really doesn't look like the appropriate answer without reading your comment about indentation...

0

精彩评论

暂无评论...
验证码 换一张
取 消