Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 996085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:49:24+00:00 2026-05-16T06:49:24+00:00

While composing documentation, I created an outline using ordered lists within ordered lists and

  • 0

While composing documentation, I created an outline using ordered lists within ordered lists and applied a pseudo-legal-style row numbering using CSS. The default behavior of lists is to right-align numbers and left align text; however, the CSS2 snippet I’m using is changing that behavior so that numbers are left-aligned and text, though left-aligned flows incorrectly. See the following examples:

Default behavior (Number 10 highlights the desired alignments):

 1. Item
 2. Item
    1. Item
    2. Item
       1. Item
       2. Item
 3. Item
 ...
10. Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
    Nunc et diam sem.   Pellentesque vitae dolor id eros commodo 
    dapibus tristique sit amet eros. Pellentesque turpis turpis.

Styled behavior (Number 10 highlights the undesirable alignments):
Using a derived CSS2 snippet from http://www.w3.org/TR/CSS2/generate.html

OL { counter-reset: item }
LI { display: block }
LI:before { content: "("counters(item, ".") ") "; counter-increment: item }

Results:

 (1) Item
 (2) Item
     (2.1) Item
     (2.2) Item
           (2.2.1) Item
           (2.2.2) Item
 (3) Item
 ...
 (10) Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
 Nunc et diam sem.   Pellentesque vitae dolor id eros commodo 
 dapibus tristique sit amet eros. Pellentesque turpis turpis.

I see that the LI { display: block } is suppressing the default numbering and LI:before is prefixing “normal” text with counter values. How can I have both legal-style numbering and desired alignment of numbers and text?

Here’s a full document showing the issue:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Outline</title>
<style type="text/css">
ol {
counter-reset: item;
list-style-position: outside
}
li {
display: block;
padding-left: 10px;
}
li:before {
content: "("counters(item, ".") ") ";
counter-increment: item
}
</style>
</head>

<body>
<h1>Outline</h1>
<ol>
  <li>Item</li>
  <li>Item
    <ol>
      <li>Item</li>
      <li>Item
        <ol>
          <li>Item</li>
          <li>Item</li>
        </ol>
      </li>
    </ol>
  </li>
  <li>Item</li>
  <li>Item</li>
  <li>Item</li>
  <li>Item</li>
  <li>Item</li>
  <li>Item</li>
  <li>Item</li>
  <li>Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
    Nunc et diam sem.   Pellentesque vitae dolor id eros commodo 
    dapibus tristique sit amet eros. Pellentesque turpis turpis.</li>
</ol>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:49:24+00:00Added an answer on May 16, 2026 at 6:49 am

    A slightly awkward solution might be:

    ol {
        width: 10em;
        counter-reset: item;
        list-style-position: outside;
    }
    
    li {
        position: relative;
        left: 2em;
        display: block;
        list-style-position: outside;
    }
    
    li:before {
        content: "("counters(item, ".") ") ";
        counter-increment: item;
        position: absolute;
        left: -2.5em;
    }
    
    li li:before {
        left: -2.5em;
    }
    
    li li li:before {
        left: -3em;
    }
    

    This just uses position: relative; to allow the li text to be moved to the right (left: 2em;) while positioning the li:before text absolutely and moving it to the left.

    The awkward part comes from having to specify different left: values for the li:before, li li:beforeandli li li:before` so it’s not quite as simple as it might be.

    There’s a demo of what I came up with over at: http://jsbin.com/asaru3


    Edited in response to comments from OP:

    Thanks, I believe I understand how that works. To continue the pattern, I’d have to create “li li li li” for a list that was 4 levels deep, right? Also, I don’t see that the numbers are left-aligned. Is there a way to get at those value and apply similar repositioning or alignment to just them?

    I mean the numbers are NOT right-aligned.

    To the first question ‘to continue the pattern, I’d have to create “li li li [li:before]” for a list…4 levels deep?” Yeah, which is one of the reasons I think it’s an awkward solution. Albeit it does work.

    To address the latter question, I believe that you want the numbers to align along their right edge?

    If you revise the css for li:before:

    li:before {
        content: "("counters(item, ".") ") ";
        counter-increment: item;
        position: absolute;
        left: -2.5em;
        display: block;
        width: 2em; /* to give the same dimensions to all counter 'blocks' */
        text-align: right; /* does exactly what you'd think =) */
    }
    

    With this approach bear in mind that the size of the contents of li:before must be less than the left: positioning of the li, otherwise there’ll be overlap of the counter and the content.

    Be aware that as the counter grows in size its width should also be amended for li li:before, li li li:before as before.

    Demo at: http://jsbin.com/ovuru3

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 530k
  • Answers 530k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Rather than fight it; maybe approach the problem from another… May 16, 2026 at 11:29 pm
  • Editorial Team
    Editorial Team added an answer Well, nothing is removed from memory so far , it… May 16, 2026 at 11:29 pm
  • Editorial Team
    Editorial Team added an answer How about finding if there are any empty elements in… May 16, 2026 at 11:29 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

This is part observation, part question. First the observation: While everyone talks of modular
I have some doubts while comparing C++ and Java multiple inheritance. Even Java uses
I am trying to get the following output : <name><![CDATA[ SomeNameHere ]]></name> using the
I've been programming in Scala for a while and I like it but one
Ninite.com seems to be doing it currently. I'm wondering how. While it's possible for
I am looking for a solution which would allow me to code for Linux
First, context: I'm trying to create a command-line-based tool (Linux) that requires login. Accounts
Let's say I have some code that does some floating point arithmetic and stores
This one has been driving me nuts for a few days now and I've
I am new to Clojure, and am beginning to experiment with building an application.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.