Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthormista3
    • CommentTimeMar 22nd 2006 edited
     permalink
    Hey folks,

    I'm in the middle of a rush job to build a site in 2 days... arghh.... (having to use tables instead of proper css, the shame)

    Can't figure out if I can force an ordered list to prefix the numbers with something... so it would look like this:

    2.1 Item One
    2.2 Item Two
    3.3 Item Three
    3.4 Item Four

    Is this possible? (Without making a custom bullet point for each item in the list)
    • CommentAuthormaspick
    • CommentTimeMar 22nd 2006
     permalink
    James -

    Are you wanting to have the OL produce the digit-dot-digit number automatically? If so, I'm not aware of that being possible using only HTML. You'd have to employ some javascript to re-write the numbering for you.

    That's my 2 cents :^{>
    • CommentAuthormista3
    • CommentTimeMar 22nd 2006
     permalink
    Yeah that was the idea... I've resorted to using an unordered list and including the numbers myself for the moment... javascript sounds like over-egging the ole pudding :-!
    • CommentAuthorKanashii
    • CommentTimeMar 22nd 2006 edited
     permalink

    You can do it however it will only work in real browsers that properly implement CSS. So mostly anything but IE.


    Depending on how you want the numbered, the things you need to know are the following.


    CSS properties
    counter-reset: counter-name value;
    counter-increment: counter-name;
    content: counter(counter-name) '.' counter(other-counter);

    And to apply the content attribute you use a :before psuedo-selector.


    And for an example of how to do the example you gave:



    CSS
    ul { counter-reset: list1 1 list2 0; list-style-type: none; }
    ul li { counter-increment: list1; }
    ul li ul { counter-reset: list; }
    ul li ul li { counter-increment: list2; }
    ul li ul li:before { content: counter(list1) '.' counter(list2) ' '; }
    HTML
    <ul>
    <li>
    <ul>
    <li>Item 1</li>
    <li>Item 2</li>
    </ul>
    </li>
    <li>
    <ul>
    <li>Item 3</li>
    <li>Item 4</li>
    </ul>
    </li>
    </ul>
    Output:
    2.1 Item 1
    2.2 Item 2
    3.3 Item 3
    3.4 Item 4

    Counters are a beautiful thing. You should see them on a 5 deep definition list for an faq. Its a sight to behold :D

  1.  permalink
Add your comments
    Username Password
  • Format comments as (Help)