Three level decimal ordered list CSS

前端 未结 2 1493
孤城傲影
孤城傲影 2021-01-28 03:43

I have a three level ordered list in html that I would like to give a style as following:

1. Item 1
1.1 Item 2
1.1.1 Item 3

An example of the

相关标签:
2条回答
  • 2021-01-28 03:54

    your css code is almost fine, see http://plnkr.co/edit/wmGhz7V6CKqZ7MmHIoDF?p=preview

    you have an extra </li><li> after level 1, so your markup becomes

    <ol>
        <li> Should be Item 1
           <ol>
               <li> Should be Item 1.1</li>
               <li> Should be Item 1.2</li>
               <li> Should be Item 1.3
                   <ol>
                       <li> Should be Item 1.3.1</li>
                   </ol>
               </li>
               <li>Should be Item 1.4</li> 
           </ol> 
        </li>
        <li> Should be Item 2</li> 
     </ol>
    

    and in your css I've removed the base list style for ol with list-style: none;

    0 讨论(0)
  • 2021-01-28 04:14

    Use the following code:

    html:

     <ol>
        <li> Should be Item 1        
          <ol>
            <li> Should be Item 1.1</li>
            <li> Should be Item 1.2</li>
            <li> Should be Item 1.3
              <ol>
                <li> Should be Item 1.3.1
              </ol>
            <li>Should be Item 1.4</li> 
          </ol> 
        </li>
        <li> Should be Item 2</li> 
        </ol>
    

    css:

    ol { counter-reset: item }
    ol li { display: block }
    ol li:before { content: counters(item, ".") ". "; counter-increment: item }
    
    0 讨论(0)
提交回复
热议问题