1

Is it possible to create a ordered list with html/css like this :

<ol>
  <li>One</li>
  <li>Two</li>
</ol>

Where they would render like this (including parenthesis):

(1) One
(2) Two
2

3 Answers 3

2

Yes you can. Try the following code. It might not work in old versions of IE or Firefox.

UPDATED: Here is a JSFiddle.

CSS:

ol {
  counter-reset: list;
}
ol li {
  list-style: none;
}
ol li:before {
  content: "(" counter(list) ") ";
  counter-increment: list;
}

HTML:

<ol>
  <li>Number 1</li>
  <li>Number 2</li>
  <li>Number 3</li>
  <li>Number 4</li>
  <li>Number 5</li>
  <li>Number 6</li>
</ol>
Sign up to request clarification or add additional context in comments.

2 Comments

@ErikMes: You must be doing something wrong then - every version of Firefox in existence has supported CSS counters from the get-go.
Good idea. If you want to know more why? You can click here.w3cplus.com/css3/css-generated-content-counters.html
1

Check out css counters. Here's a fiddle.

markup:

<ol>
  <li>One</li>
  <li>Two</li>
</ol>

css:

ol
{
    counter-reset: section; 
    list-style: none;
}
li:before
{
    counter-increment: section;
    content: "(" counter(section) ") ";    
}

2 Comments

There's a very good Smashing article about it : coding.smashingmagazine.com/2013/04/12/…
@crush Doesn't matter... you don't have to be first to get rep. ;)
1

See the following JSFiddle: http://jsfiddle.net/VzEsr/

HTML

<ol>
  <li>One</li>
  <li>Two</li>
</ol>

CSS

ol {
    list-style: none;
    counter-reset: count 0;
}

ol li {
    counter-increment: count 1;
}

ol li:before {
    content: '(' counter(count) ')';
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.