Multiple CSS counters not working as expected -


i trying create multiple levels of counters in html table, not working expected. first counter works ok, next counters not work. somehow counters not incrementing or reset wrongly?

the code:

<html>   <head>     <title>counter demo</title>     <style>       table.tasksteps {           counter-reset: tasksteps;       }        td.taskstep {           counter-reset: risks;           counter-increment: tasksteps;       }        td.risk {           counter-reset: measures;           counter-increment: risks;       }        td.measure {           counter-increment: measures;       }        td.taskstep:before {           content: counter(tasksteps) '. ';       }        td.risk:before {           content: counter(tasksteps) '.' counter(risks) '. ';       }        td.measure:before {           content: counter(tasksteps) '.' counter(risks) '.' counter(measures) '. ';       }  </style>   </head>   <body>     <table class="tasksteps">       <thead>         <tr>           <td>taakstep</td>           <td>risk</td>           <td>measure</td>         </tr>       </thead>       <tbody>         <tr>           <td class="taskstep t1">step 1</td>           <td></td>           <td></td>         </tr>         <tr>           <td class="taskstep t2">step 2</td>           <td class="risk">risk 1</td>           <td></td>         </tr>         <tr>           <td class="t3"></td>           <td class="risk">risk 2</td>           <td></td>         </tr>         <tr>           <td class="taskstep t2">step 3</td>           <td class="risk">risk 3</td>           <td></td>         </tr>         <tr>           <td class="taskstep t2">step 4</td>           <td class="risk">risk 4</td>           <td></td>         </tr>         <tr>           <td class="t4"></td>           <td class="risk">risk 5</td>           <td class="measure">measure 1</td>         </tr>         <tr>           <td class="t5"></td>           <td></td>           <td class="measure">measure 2</td>         </tr>         <tr>           <td class="t5"></td>           <td></td>           <td class="measure">measure 3</td>         </tr>         <tr>           <td class="t5"></td>           <td></td>           <td class="measure">measure 4</td>         </tr>         <tr>           <td class="t3"></td>           <td class="risk">risk 6</td>           <td></td>         </tr>         <tr>           <td class="t4"></td>           <td class="risk">risk 7</td>           <td class="measure">measure 5</td>         </tr>       </tbody>     </table>   </body> </html> 

this gives output:
output above code

fiddle

there 2 problems here:

  1. the direct parent of first counted element should contain other counted elements. in case, first counted element td in row, parent tr but other counted elements have own parents of tr (which siblings of parent of first counted element). fix think have set class on tr , count there.

  2. the counter-reset , counter-increment can overridden, means if @ 1 tr, need use counter-reset , counter-increment more 1 counter variable, need put them on same declaration (space-separated) counter-reset , counter-increment.

from 2 points above, here code should be:

html:

<table class="tasksteps">   <thead>     <tr>       <td>taakstep</td>       <td>risk</td>       <td>measure</td>     </tr>   </thead>   <tbody>             <tr class="taskstep">       <td class="taskstep t1">step 1</td>       <td></td>       <td></td>     </tr>     <tr class="taskstep risk">       <td class="taskstep t2">step 2</td>       <td class="risk">risk 1</td>       <td></td>     </tr>     <tr class="risk">       <td class="t3"></td>       <td class="risk">risk 2</td>       <td></td>     </tr>     <tr class="taskstep risk">       <td class="taskstep t2">step 3</td>       <td class="risk">risk 3</td>       <td></td>     </tr>     <tr class="taskstep risk">       <td class="taskstep t2">step 4</td>       <td class="risk">risk 4</td>       <td></td>     </tr>     <tr class="risk">       <td class="t4"></td>       <td class="risk">risk 5</td>       <td class="measure">measure 1</td>     </tr>     <tr>       <td class="t5"></td>       <td></td>       <td class="measure">measure 2</td>     </tr>     <tr>       <td class="t5"></td>       <td></td>       <td class="measure">measure 3</td>     </tr>     <tr>       <td class="t5"></td>       <td></td>       <td class="measure">measure 4</td>     </tr>     <tr class="risk">       <td class="t3"></td>       <td class="risk">risk 6</td>       <td></td>     </tr>     <tr class="risk">       <td class="t4"></td>       <td class="risk">risk 7</td>       <td class="measure">measure 5</td>     </tr>   </tbody> </table> 

css:

  table.tasksteps {       counter-reset: tasksteps;   }         tr.taskstep {       counter-reset: risks;       counter-increment: tasksteps;   }       tr.risk {                 counter-reset: measures;       counter-increment: risks;   }   tr.taskstep.risk {       counter-reset: risks measures;       counter-increment: tasksteps risks;   }   td.measure {       counter-increment: measures;   }    td.taskstep:before {       content: counter(tasksteps) '. ';   }    td.risk:before {       content: counter(tasksteps) '.' counter(risks) '. ';   }    td.measure:before {       content: counter(tasksteps) '.' counter(risks) '.' counter(measures) '. ';   }     

updated demo.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -