Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a binary counter with the <ol> tag?

Tags:

html

css

I thought that I could do the following:

<ol style = "type:numeric; glyphs: '0' '1';">
    <li> Item 0 </li>
    <li> Item 1 </li>
    <li> Item 2 </li>
</ol>

to produce a list that counted in binary. That is, the above example should have produced:

0. Item 0

1. Item 1

10. Item 2

But alas, it did no such thing. Firefox just ignored my style suggestions.

I was reading about this on http://www.w3.org/TR/css3-lists/ (section 8.1.2)

But clearly I've misread / misunderstood the specification. Any help?

Thank you!

like image 965
B Rivera Avatar asked Sep 04 '13 15:09

B Rivera


People also ask

What is OL tag in HTML?

The <ol> HTML element represents an ordered list of items — typically rendered as a numbered list.

How do you make a numbered list in HTML?

Using HTML, you can create two kinds of lists unordered list and ordered list. An ordered list is marked with the numbers by default. You can create an ordered list using the <ol></ol> tag and, define the list items using <li></li>. type="1"− This creates a numbered list starting from 1.

What is OL and UL in HTML?

The ol element is used when the list is ordered and the ul element is used when the list is unordered. Definition lists ( dl ) are used to group terms with their definitions. Although the use of this markup can make lists more readable, not all lists need markup.

How do you start an ordered list from an alphabet in HTML?

An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.


2 Answers

If you want to do it visible in every browser, you need to do it with another language (javascript/jquery, or with something comming from your server)

In the end, you just need to have something like that : http://jsfiddle.net/KdhxX/

<ol>
  <li value="0"> Item 0 </li>
  <li value="1"> Item 1 </li>
  <li value="10"> Item 2 </li>
</ol>

with the value inserted inside your "li" populated by javascript, or your server-side language

like image 32
Deblaton Jean-Philippe Avatar answered Oct 19 '22 00:10

Deblaton Jean-Philippe


The type and glyphs properties go in side a @counter-style declaration, so you need to define counter style then use it.

@counter-style mybinary {
    type: numeric;
    glyphs: '0' '1' '2';
}

<ol style = "list-style-type:mybinary;">
    <li> Item 0 </li>
    <li> Item 1 </li>
    <li> Item 2 </li>
</ol>

I don't think any browser implements this though as this is all I found on it besides the working draft and this line from MDN

CSS Lists and Counters Module Level 3 Working Draft Adds support for and adds identifiers used in @counter-style rules to keywords. These changes are not yet reflected on this page as no browser currently implements them.

like image 94
Musa Avatar answered Oct 19 '22 00:10

Musa