Reversing order of ordered list counter in CSS -


i have snippet let better understand question:

$(window).load(function() {    var total;      $(document).ready(function() {      $('#dupe').click(function() {        $('#uploadforms').prepend($('#htmltemplate').html());        $($('#uploadforms .upload_form')[0]).animate({          height: $($('#uploadforms .upload_form')[$('#uploadforms .upload_form').size() - 1]).css('height'),          opacity: 1        }, 500);        totalforms();          $(".upload_form").each(function() {          if (typeof $(this).find('a.close')[0] === 'undefined') {            if ($('#uploadforms .upload_form').size() > 1) $(this).prepend('<a class="close">x</a>');          }        });          $(".upload_form").on("click", ".close", function() {          $(this).parent().animate({            height: 0,            opacity: 0,            paddingtop: 0,            paddingbottom: 0          }, 500, function() {            $(this).parent().remove();            totalforms()          });          if ($('#uploadforms .upload_form').size() - 1 <= 1) $('#uploadforms .upload_form').find('a.close').remove();        });      });        function totalforms() {        total = $('#uploadforms .upload_form').size();        $('#total').html(total);      }    });  });
.upload_form {    background-color: rgba(0, 0, 0, .3);    padding: 16px 64px 10px 76px;    border-bottom-left-radius: 15px;    border-bottom-right-radius: 15px;    margin-bottom: 10px;  }  .coverart {    margin-right: 48px;    margin-bottom: 36px;  }  label input,  label textarea {    width: 252px;  }  .info {    display: block;    vertical-align: top;  }  .close {    float: right;    color: white;    margin: 10px;    display: block;    cursor: hand;    border-radius: 100%;    cursor: pointer;    width: 18px;    height: 18px;    text-align: center;    -moz-user-select: none;    -webkit-user-select: none;  }  .close:hover {    background-color: rgba(0, 0, 0, 0.5);  }  ol {    counter-reset: li;    margin-left: 0;    padding-left: 0;  }  ol > li {    position: relative;    margin: 0 0 6px 2em;    padding: 0px 0px 8px;    list-style: none;    border-top: 2px solid #666;  }  ol > li:before {    content: counter(li);    counter-increment: li;    position: absolute;    top: -2px;    left: -2em;    -moz-box-sizing: border-box;    -webkit-box-sizing: border-box;    box-sizing: border-box;    width: 2em;    margin-right: 8px;    padding: 4px;    border-top: 2px solid #666;    color: #fff;    background: #666;    font-weight: bold;    font-family: "helvetica neue", arial, sans-serif;    text-align: center;  }  li ol,  li ul {    margin-top: 6px;  }  ol ol li:last-child {    margin-bottom: 0;  }  .template {    display: none  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>  <input type="button" value="add file..." id="dupe">  <input type="button" value="upload file(s)" id="dupe">    <hr>    <p>total: <span id="total">1</span></p>    <div id="htmltemplate" class="template">    <li>      <div class="upload_form" style="height:0;opacity:0;">        <span class="number"></span>        <a class="close">x</a>        <div class="info">          <p>filler</p>        </div>      </div>    </li>  </div>    <ol id="uploadforms">    <li>      <div class="upload_form">        <span class="number"></span>        <a class="close">x</a>        <div class="info">          <p>filler</p>        </div>      </div>    </li>  </ol>

in demo if click "add file..." new list element added new <div> inside. question is: how reverse order of counter?

related css:

ol {     counter-reset:li; } ol > li {     position:relative;     margin:0 0 6px 2em;     padding: 0px 0px 8px;     list-style:none;     border-top:2px solid #666; } ol > li:before {     content: counter(li);     counter-increment:li;     position:absolute;     top:-2px;     left:-2em;     box-sizing:border-box;     width:2em;     margin-right:8px;     padding:4px;     border-top:2px solid #666;     color:#fff;     background:#666;     font-weight:bold;     font-family:"helvetica neue", arial, sans-serif;     text-align:center; } 

i don't have pure css solution, page quite js-heavy, think okay.

for li add

counter-increment: li -1; 

to make count backwards. means can't reset @ 0, has reset @ total elements.

for ol start with

counter-reset:li 2; 

and update js:

$('#total').html(total); $("ol").css('counter-reset', 'li ' + (+total + 1)); 

http://jsfiddle.net/explosionpills/arzuw/1/


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -