{"id":51575,"date":"2021-02-02T03:01:11","date_gmt":"2021-02-01T17:01:11","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=51575"},"modified":"2021-01-31T21:34:48","modified_gmt":"2021-01-31T11:34:48","slug":"css-countdown-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/css-countdown-primer-tutorial\/","title":{"rendered":"CSS Countdown Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/css_count_image.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"CSS Countdown Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/css_count_image.gif\" title=\"CSS Countdown Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">CSS Countdown Primer Tutorial<\/p><\/div>\n<p>It&#8217;s not normally a talent you associate with CSS, the ability to do any maths, but you can count (or increment\/decrement) with it, with <font color=blue>styling like<\/font> &#8230;<\/p>\n<p><code><br \/>\n&lt;style&gt;<br \/>\n#myspan {<br \/>\n  counter-reset: the-final-countdown <font color=blue>var(--tooltip-string)<\/font>;<br \/>\n  line-height: 2;<br \/>\n}<br \/>\n<br \/>\ndiv::before {<br \/>\n  <font color=blue>counter-increment: the-final-countdown -1;<\/font><br \/>\n  content: \"~\" counter(the-final-countdown) \"~\";<br \/>\n  background: yellow;<br \/>\n  display: inline-block;<br \/>\n  width: 20rem;<br \/>\n  margin-right: 0.5rem;<br \/>\n  text-align: center;<br \/>\n}<br \/>\n<br \/>\ndiv::after {<br \/>\n  content: <font color=purple>var(--tooltip-string)<\/font>;<br \/>\n}<br \/>\n&lt;\/style&gt;<br \/>\n<\/code>  <\/p>\n<p> &#8230; and did you see above it can work with var<font size=1>iables<\/font> as another Javascript type talent?<\/p>\n<p>As a Javascript coder knows, once you have var<font size=1>iables<\/font> to play with, they can represent other useful things.<\/p>\n<p>Let&#8217;s establish a CSS var<font size=1>iable<\/font> via (HTML like) &#8230;<\/p>\n<p><code><br \/>\n&lt;span id=myspan style=\"<font color=blue>--tooltip-string:12;<\/font>\"&gt;&lt;\/span&gt;<br \/>\n<\/code><\/p>\n<p> &#8230; then that &#8220;12&#8221; gets substituted so that &#8230;<\/p>\n<p><code><br \/>\n&lt;style&gt;<br \/>\n#myspan {<br \/>\n  counter-reset: the-final-countdown <font color=blue>12<\/font>;<br \/>\n  line-height: 2;<br \/>\n}<br \/>\n&lt;\/style&gt;<br \/>\n<\/code><\/p>\n<p> &#8230; and more adventurously we can use Javascript <font color=purple>such as<\/font> &#8230;<\/p>\n<p><code><br \/>\n  function thisdecodeURIComponent(inname, inval) {<br \/>\n   var outval=decodeURIComponent(inval), dwiurl='';<br \/>\n   if (inval != '') {<br \/>\n     icnt=eval(inname.replace('dw',''));<br \/>\n     dwiurl=(location.search.split(inname.replace('dw', 'di') + '=')[1] ? decodeURIComponent(location.search.split(inname.replace('dw', 'di') + '=')[1].split('&')[0]) : '');<br \/>\n     if (dwiurl != '') {<br \/>\n       outval='&lt;div style=\"<font color=purple>--tooltip-string:url(' + dwiurl + ')<\/font>;\"&gt;' + inval + '&lt;\/div&gt;';<br \/>\n     } else {<br \/>\n       outval='&lt;div&gt;' + inval + '&lt;\/div&gt;';<br \/>\n     }<br \/>\n     spanstr=\"&lt;span id=myspan style='--tooltip-string:\" + icnt + \";'&gt;&lt;h1&gt;CSS counter via var&lt;\/h1&gt;&lt;h3&gt;RJM Programming - February, 2021&lt;\/h3&gt;&lt;h4&gt;Thanks to &lt;a target=_blank title='https:\/\/css-tricks.com\/valid-css-content\/' href='https:\/\/css-tricks.com\/valid-css-content\/'&gt;https:\/\/css-tricks.com\/valid-css-content\/&lt;\/a&gt;&lt;\/h4&gt;&lt;\/span&gt;\";<br \/>\n     icnt++;<br \/>\n     while (inval != '') {<br \/>\n        inval=(location.search.split('dw' + icnt + '=')[1] ? decodeURIComponent(location.search.split('dw' + icnt + '=')[1].split('&')[0]) : '');<br \/>\n        if (inval != '') {<br \/>\n          spanstr=\"&lt;span id=myspan style='--tooltip-string:\" + icnt + \";'&gt;&lt;h1&gt;CSS counter via var&lt;\/h1&gt;&lt;h3&gt;RJM Programming - February, 2021&lt;\/h3&gt;&lt;h4&gt;Thanks to &lt;a target=_blank title='https:\/\/css-tricks.com\/valid-css-content\/' href='https:\/\/css-tricks.com\/valid-css-content\/'&gt;https:\/\/css-tricks.com\/valid-css-content\/&lt;\/a&gt;&lt;\/h4&gt;&lt;\/span&gt;\";<br \/>\n          inname='dw' + icnt;<br \/>\n     dwiurl=(location.search.split(inname.replace('dw', 'di') + '=')[1] ? decodeURIComponent(location.search.split(inname.replace('dw', 'di') + '=')[1].split('&')[0]) : '');<br \/>\n     if (dwiurl != '') {<br \/>\n       outval+='&lt;div style=\"<font color=purple>--tooltip-string:url(' + dwiurl + ')<\/font>;\"&gt;' + inval + '&lt;\/div&gt;';<br \/>\n     } else {<br \/>\n       outval+='&lt;div&gt;' + inval + '&lt;\/div&gt;';<br \/>\n     }<br \/>\n        }<br \/>\n        icnt++;<br \/>\n     }<br \/>\n   }<br \/>\n   return outval;<br \/>\n  }<br \/>\n<\/code><\/p>\n<p> &#8230; to get CSS to display an image via a CSS var<font size=1>iable<\/font> associated with a particular &#8220;CSS &#8220;counter&#8221; instance <font size=-1>(if you will)<\/font>.  Cute, huh?!<\/p>\n<p>Thanks to <a target=_blank title='https:\/\/css-tricks.com\/valid-css-content\/' href='https:\/\/css-tricks.com\/valid-css-content\/'>https:\/\/css-tricks.com\/valid-css-content\/<\/a>, see how this can work in practice with today&#8217;s &#8220;proof of concept&#8221; <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/css_count_image.html_GETME\" title=\"css_count_image.html\">css_count_image.html<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/css_count_image.html\" title=\"Click picture\">live run<\/a> &#8230;<\/p>\n<p><iframe style='width:95%;height:600px;' title='Proof of concept' src='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/css_count_image.html'><\/iframe><\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d51575' onclick='var dv=document.getElementById(\"d51575\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/counter\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d51575' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s not normally a talent you associate with CSS, the ability to do any maths, but you can count (or increment\/decrement) with it, with styling like &#8230; &lt;style&gt; #myspan { counter-reset: the-final-countdown var(&#8211;tooltip-string); line-height: 2; } div::before { counter-increment: the-final-countdown &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/css-countdown-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,37],"tags":[3291,281,576,3554,652,997,1319,1345,3553,1721],"class_list":["post-51575","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-counter","tag-css","tag-html","tag-image-url","tag-javascript","tag-programming","tag-tutorial","tag-url","tag-var","tag-variable"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/51575"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=51575"}],"version-history":[{"count":8,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/51575\/revisions"}],"predecessor-version":[{"id":51583,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/51575\/revisions\/51583"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=51575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=51575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=51575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}