<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://logicwiki.co.uk/index.php?action=history&amp;feed=atom&amp;title=Css_Variables</id>
		<title>Css Variables - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://logicwiki.co.uk/index.php?action=history&amp;feed=atom&amp;title=Css_Variables"/>
		<link rel="alternate" type="text/html" href="http://logicwiki.co.uk/index.php?title=Css_Variables&amp;action=history"/>
		<updated>2026-06-06T16:12:42Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://logicwiki.co.uk/index.php?title=Css_Variables&amp;diff=1515&amp;oldid=prev</id>
		<title>AliIybar: Created page with &quot;Category:CSS  To declare a variable, you first need to decide which scope the variable should live in. If you want it to be available globally, simply define it on the '''...&quot;</title>
		<link rel="alternate" type="text/html" href="http://logicwiki.co.uk/index.php?title=Css_Variables&amp;diff=1515&amp;oldid=prev"/>
				<updated>2018-09-05T13:09:32Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&lt;a href=&quot;/index.php?title=Category:CSS&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Category:CSS (page does not exist)&quot;&gt;Category:CSS&lt;/a&gt;  To declare a variable, you first need to decide which scope the variable should live in. If you want it to be available globally, simply define it on the &amp;#039;&amp;#039;&amp;#039;...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:CSS]]&lt;br /&gt;
&lt;br /&gt;
To declare a variable, you first need to decide which scope the variable should live in. If you want it to be available globally, simply define it on the ''':root pseudo class.''' It matches the root element in your document tree (usually the &amp;lt;html&amp;gt; tag).&lt;br /&gt;
&lt;br /&gt;
 :root {&lt;br /&gt;
   --main-color: #ff6f69;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The variable must start with '''two dashes'''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To access a variable, you need to use the '''var()''' function, and pass in the name of the variable as the parameter.&lt;br /&gt;
 #title {&lt;br /&gt;
   color: var(--main-color);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Declaring a local variable ==&lt;br /&gt;
&lt;br /&gt;
You can also create local variables, which are accessible only to the element it’s declared at and to its children. This makes sense to do if you know that a variable only will be used in a specific part (or parts) of your app.&lt;br /&gt;
&lt;br /&gt;
For example, you might have an alert box which uses a special kind of color which aren’t being used other places in the app. In that case, it might make sense to avoid placing it in the global scope:&lt;br /&gt;
&lt;br /&gt;
 .alert {&lt;br /&gt;
   --alert-color: #ff6f69;&lt;br /&gt;
 }&lt;br /&gt;
This variable can now be used by its children:&lt;br /&gt;
&lt;br /&gt;
 .alert p {&lt;br /&gt;
   color: var(--alert-color);&lt;br /&gt;
   border: 1px solid var(--alert-color);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Responsiveness ==&lt;br /&gt;
 :root {&lt;br /&gt;
   --main-font-size: 16px;&lt;br /&gt;
 }&lt;br /&gt;
 media all and (max-width: 600px) {&lt;br /&gt;
   :root {&lt;br /&gt;
     --main-font-size: 12px;&lt;br /&gt;
   }&lt;br /&gt;
 }&lt;br /&gt;
And with those simple four lines of code you have updated the main font size across your entire app when viewed on small screens&lt;br /&gt;
&lt;br /&gt;
== Accessing variables with JavaScript ==&lt;br /&gt;
 var root = document.querySelector(':root');&lt;br /&gt;
 var rootStyles = getComputedStyle(root);&lt;br /&gt;
 var mainColor = rootStyles.getPropertyValue('--main-color');&lt;br /&gt;
 console.log(mainColor); &lt;br /&gt;
 --&amp;gt; '#ffeead'&lt;br /&gt;
To update the CSS Variable simply call the setProperty method &lt;br /&gt;
 root.style.setProperty('--main-color', '#88d8b0')&lt;br /&gt;
&lt;br /&gt;
-----&lt;br /&gt;
See Also [https://scrimba.com/g/gcssvariables https://scrimba.com/g/gcssvariables]&lt;/div&gt;</summary>
		<author><name>AliIybar</name></author>	</entry>

	</feed>