赞
踩
用 counter-reset,结合counter-increment和content,可以做一些简单的计算。
counter-reset属性创建或重置一个或多个计数器。
counter-increment 属性设置某个选取器每次出现的计数器增量。默认增量是 1。
counter()插入计数器。只能被使用在content属性上。如果想重复多次计数器可以使用 counters()
例如如下图:
- <!-- html -->
- <div class="languages">
- <input id="c" type="checkbox"><label for="c">C</label>
- <input id="C++" type="checkbox"><label for="C++">C++</label>
- <input id="C#" type="checkbox"><label for="C#">C#</label>
- <input id="Java" type="checkbox"><label for="Java">Java</label>
- <input id="JavaScript" type="checkbox"><label for="JavaScript">JavaScript</label>
- <input id="PHP" type="checkbox"><label for="PHP">PHP</label>
- <input id="Python" type="checkbox"><label for="Python">Python</label>
- <input id="Ruby" type="checkbox"><label for="Ruby">Ruby</label>
- </div>
- <p class="total">
- Total selected:
- </p>
-
- .languages {
- counter-reset: characters;
- }
- input:checked {
- counter-increment: characters;
- }
- .total:after {
- content: counter(characters);
- }
注:characters 是自定义的。
还可以做计算:
- <!-- html -->
- <div class="numbers">
- <input id="one" type="checkbox"><label for="one">1</label>
- <input id="two" type="checkbox"><label for="two">2</label>
- <input id="three" type="checkbox"><label for="three">3</label>
- <input id="four" type="checkbox"><label for="four">4</label>
- <input id="five" type="checkbox"><label for="five">5</label>
- <input id="one-hundred" type="checkbox"><label for="one-hundred">100</label>
- </div>
- <p class="sum">
- Sum
- </p>
-
- .numbers {
- counter-reset: sum;
- }
-
- #one:checked { counter-increment: sum 1; }
- #two:checked { counter-increment: sum 2; }
- #three:checked { counter-increment: sum 3; }
- #four:checked { counter-increment: sum 4; }
- #five:checked { counter-increment: sum 5; }
- #one-hundred:checked { counter-increment: sum 100; }
-
- .sum::after {
- content: '= ' counter(sum);
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。