5

Is there any way in HTML/CSS to format a legal document that needs to stay the same as the original document format. In other words.

  1. Main heading

    1.1 Sub Heading

    1.2 Sub Heading

    1.3 Sub Heading

    1.3.1 Sub Sub Heading
    
    1.3.2 Sub Sub Heading
    

    1.4 Sub Heading

  2. Main Heading

    2.1 Sub Heading

etc... etc...

I know that you can use nested OL's but this does not render what I need as above

EDIT

Of course this is wonderful until IE popped its ugly head! (I have to wonder to myself what the developers over at Microsoft must think about the millions of complaints about their product.) I found this solution http://www.sitepoint.com/techy-treasures-5-fudging-css-counters-in-internet-explorer/ and have tried implementing it.

It works partly, but I have no idea how to use this expression correctly:

  #css-counters-test li  
  {  
     zoom: expression(  
      (typeof step == "undefined" ? step = 1 : step++),  
      this.innerHTML = (typeof this.processed == "undefined"  
            ? ("<span class=before>" + step + ": </span>")  
            : "")  
        + this.innerHTML,  
      this.processed = true,  
      this.runtimeStyle.zoom = "1"  
      );  
  }
Nightfirecat
  • 11,432
  • 6
  • 35
  • 51
SixfootJames
  • 1,841
  • 5
  • 26
  • 42
  • Possible duplicate of [Can ordered list produce result that looks like 1.1, 1.2, 1.3 (instead of just 1, 2, 3, ...) with css?](https://stackoverflow.com/questions/4098195/can-ordered-list-produce-result-that-looks-like-1-1-1-2-1-3-instead-of-just-1) – Kay V Jan 04 '18 at 12:13

2 Answers2

7

For this type of functionality you can use counter-increment property check this:

HTML

<ol>
  <li>item 1
    <ol>
      <li>sub item 1
        <ol>
          <li>sub-sub item 1</li>
          <li>sub-sub item 2</li>
          <li>sub-sub item 3</li>
        </ol>
      </li>
      <li>Sub item 2</li>
   </ol>
  </li>
  <li>item 2</li>
</ol>

CSS

ol {
  counter-reset: section;
  list-style-type: none;
}
ol ol ol{background:#c0c0c0; padding-left:10px;}       
ol li { counter-increment: section; }

ol li:before  { content: counters(section, ".") ". "; }

An live example using this property can be found here

Related reading from the Opera dev site

codingbadger
  • 42,678
  • 13
  • 95
  • 110
sandeep
  • 91,313
  • 23
  • 137
  • 155
0

you have the right idea, just need to use {content:;} and {counter:;}

Live example can be found here

codingbadger
  • 42,678
  • 13
  • 95
  • 110
albert
  • 8,112
  • 3
  • 47
  • 63