Auto generate numbering list in HTML using CSS -


i've been working on tnc client. content have lot of <li></li> tags. in order create automated numbering, i've been using below code magic.

css :

ol {counter-reset: section;list-style-type: none;padding-left:0} ol li {counter-increment: section;font-weight:700} ol li:before {content: counters(section, ".") ". "} ol li ol {padding-left:15px} ol li ol li {margin:10px 0} ul {list-style-type:lower-alpha} ul li:before {content: ""} 

html :

<ol>     <li>     <span class="underline">title</span>         <ol>             <li>                 content             </li>             <li>                 content             </li>             <li>                 <span class="underline">sub title</span>                 <ul>                     <li>                         sub content                     </li>                     <li>                         sub content                     </li>                     <li>                         sub content                     </li>                 </ul>             </li>             <li>                 content             </li>         </ol>     </li> </ol> 

output :

check image output

jsfiddle

the problem counter seems broken after lower-alpha style list. avoid using javascript in process page called in other page using ajax.

try

ol {counter-reset: section;  list-style-type:none;padding-left:0} ol li:before {counter-increment: section;font-weight:700;content: counters(section, ".") ". "} ul {counter-reset: section;  list-style-type:lower-alpha} ul li:before {counter-increment: section; content: ""} 

working demo

update

add counter-reset on ul next (inner) listings

 ul {counter-reset: section;list-style-type:lower-alpha}  ul  li {counter-increment: section;}  ul li:before {content: ""} 

working fiddle

read more on using css counters


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -