{"id":34261,"date":"2017-11-12T03:01:34","date_gmt":"2017-11-11T17:01:34","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=34261"},"modified":"2017-11-11T13:53:48","modified_gmt":"2017-11-11T03:53:48","slug":"css-variables-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/css-variables-primer-tutorial\/","title":{"rendered":"CSS Variables Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/css_variable.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"CSS Variables Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/css_variable.jpg\" title=\"CSS Variables Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">CSS Variables Primer Tutorial<\/p><\/div>\n<p>If you are a regular reader of this blog, I hope by now you would have gleaned that a <i>big takeaway<\/i> we would have you learn here is that, very often, in programming, in Information Technology generally, there can be a myriad of ways to solve any one type of problem.   In terms of this, we are not suggesting today&#8217;s &#8220;CSS Variables&#8221; is a <i>must know<\/i> topic, rather a &#8220;that fits in with how I see the programming style I want to adopt&#8221; if this concept is new to you.<\/p>\n<p>So, CSS can use var<font size=1>iables<\/font> and into &#8220;that bargain&#8221; goes that same syntax as var<font size=1>iables<\/font> in Javascript, as per the CSS below &#8230;<\/p>\n<p><code><br \/>\n&lt;style&gt;<br \/>\nbody {<br \/>\n  --main-bg-color: brown;<br \/>\n}<br \/>\n<b><\/b><br \/>\nbody {<br \/>\n  background-color: var(--main-bg-color);<br \/>\n}<br \/>\n&lt;\/style&gt;<br \/>\n<\/code><\/p>\n<p> &#8230; and the thanks to <a target=_blank title='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Using_CSS_variables' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Using_CSS_variables'>https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Using_CSS_variables<\/a> are so profound we let the &#8220;color&#8221; ugh!! feeling go through to the keeper &#8230; which works on the two basic syntax principles &#8230;<\/p>\n<ol>\n<li>CSS var<font size=1>iables<\/font> start with <b>&#8212;<\/b> (eg. <b>&#8211;main-bg-color<\/b>)<\/li>\n<li>The use of CSS var<font size=1>iables<\/font> is via (for the example above) <b>var(<\/b>&#8211;main-bg-color<b>)<\/b><\/li>\n<\/ol>\n<p>Lately we&#8217;ve been enjoying the dynamic way CSS can (but not always without repercussions) be appended dynamically to (Javascript DOM) <i>document.body.innerHTML<\/i> to dynamically change CSS styling during webpage execution.  In today&#8217;s case the user clicks a link and a Javascript window.<a target=_blank title='Javascript prompt window information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/met_win_prompt.asp'>prompt<\/a> window&#8217;s response from the user can be used to change that webpage&#8217;s background colour, and this principle is called into play.<\/p>\n<p>Either link to today&#8217;s HTML and CSS and Javascript <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/css_variable.html_GETME\" title=\"css_variable.html\">css_variable.html<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/css_variable.html\" title=\"Click picture\">live run<\/a> or see it in its entirety below &#8230;<\/p>\n<p><code><br \/>\n&lt;!doctype html&gt;<br \/>\n&lt;html&gt;<br \/>\n&lt;head&gt;<br \/>\n&lt;title&gt;CSS Variables - RJM Programming - November, 2017&lt;\/title&gt;<br \/>\n&lt;style&gt;<br \/>\nbody {<br \/>\n  --main-bg-color: brown;<br \/>\n}<br \/>\n<b><\/b><br \/>\nbody {<br \/>\n  background-color: var(--main-bg-color);<br \/>\n}<br \/>\n&lt;\/style&gt;<br \/>\n&lt;script type='text\/javascript'&gt;<br \/>\n var mybodyc='', mybodyi='';<br \/>\n<b><\/b><br \/>\n function changethings() {<br \/>\n   var newc=null;<br \/>\n   if (mybodyc == '') {<br \/>\n     newc=prompt('Describe a colour as the background colour eg. red or #ff0000', 'red');<br \/>\n     if (newc != null) {<br \/>\n      if (newc != '') {<br \/>\n       mybodyc=newc;<br \/>\n       document.getElementById('mya').innerHTML=newc;<br \/>\n       document.body.innerHTML+=' &lt;style&gt; .mybodyc {  --main-bg-color: ' + newc + '; } &lt;\/style&gt; ';<br \/>\n      }<br \/>\n     }<br \/>\n   } else {<br \/>\n     newc=prompt('Describe a colour as the background colour eg. green or #00ff00', 'green');<br \/>\n     if (newc != null) {<br \/>\n      if (newc != '') {<br \/>\n       document.getElementById('mya').innerHTML=newc;<br \/>\n       document.body.innerHTML+=' &lt;style&gt; #mybodyi {  --main-bg-color: ' + newc + '; } &lt;\/style&gt; ';<br \/>\n      }<br \/>\n     }<br \/>\n   }<br \/>\n }<br \/>\n&lt;\/script&gt;<br \/>\n&lt;\/head&gt;<br \/>\n&lt;body id='mybodyi' class='mybodyc'&gt;<br \/>\n&lt;h1&gt;CSS Variables&lt;\/h1&gt;<br \/>\n&lt;h3&gt;RJM Programming - November, 2017 ... click\/touch colour description to allow for change&lt;\/h3&gt;<br \/>\n&lt;h4&gt;Thanks to &lt;a target=_blank title='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Using_CSS_variables' href='https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Using_CSS_variables'&gt;https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Using_CSS_variables&lt;\/a&gt;&lt;\/h4&gt;<br \/>\n&lt;div style=\"width:100%;margin-top:20%;text-align:center;\"&gt;<br \/>\n&lt;font size=20&lt;b&gt;&lt;i&gt;I'm &lt;a id='mya' onclick='changethings();' style='cursor:pointer;text-decoration:none;'&gt;brown&lt;\/a&gt;&lt;\/i&gt;&lt;\/b&gt;&lt;\/font&gt;<br \/>\n&lt;\/div&gt;<br \/>\n&lt;\/body&gt;<br \/>\n&lt;\/html&gt;<br \/>\n<\/code><\/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='#d34261' onclick='var dv=document.getElementById(\"d34261\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/css\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d34261' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you are a regular reader of this blog, I hope by now you would have gleaned that a big takeaway we would have you learn here is that, very often, in programming, in Information Technology generally, there can be &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/css-variables-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":[281,576,652,997,1761,1209,2386,1319,1721],"class_list":["post-34261","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-css","tag-html","tag-javascript","tag-programming","tag-prompt","tag-style","tag-syntax","tag-tutorial","tag-variable"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/34261"}],"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=34261"}],"version-history":[{"count":2,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/34261\/revisions"}],"predecessor-version":[{"id":34263,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/34261\/revisions\/34263"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=34261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=34261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=34261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}