+ 8

It is possible to create variables in CSS ?

20th Jul 2018, 7:35 PM
program
program - avatar
11 odpowiedzi
+ 15
yes element { --main-color: #adf; } and then: element { color: var(--main-color); } element is like a namespace. You can also set its in the root such way: :root { color: var(--main-color, green); /* where green is like default value*/ } By the way, you can get access to variables from javascript, but for scss variables you can't do it for example. Css is cool🌻
20th Jul 2018, 7:39 PM
Tzurumi Nakato
+ 4
Hi Tzurumi Nakato, Have you been able to get CSS variables to work in the Code Playground? I haven't been able to. 😳
21st Jul 2018, 10:50 AM
Priyank Sharma
Priyank Sharma - avatar
+ 3
Nevermind. I guess global variables must be created in :root.
21st Jul 2018, 7:27 AM
Janning⭐
Janning⭐ - avatar
+ 3
Janning⭐ Look at supporting
21st Jul 2018, 7:32 AM
Tzurumi Nakato
+ 1
Hi Tzurumi Nakato, Have you been able to get CSS variables to work in the Code Playground? I haven't been able to. 😳
21st Jul 2018, 7:20 AM
Janning⭐
Janning⭐ - avatar
+ 1
css and html aren't programming languages
22nd Jul 2018, 10:08 AM
keev23i
keev23i - avatar
+ 1
yes Variables in CSS should be declared within a CSS selector that defines its scope. For a global scope you can use either the :root or the body selector. The variable name must begin with two dashes (--) and is case sensitive! The syntax of the var() function is as follows: var(custom-name, value)
22nd Jul 2018, 1:13 PM
deepak sharma
deepak sharma - avatar
+ 1
Yeah, having to declare variables in root to make them global caught me off guard as I'm used to using a preprocessor, which allows me to just declare them outside of everything else. 👍
22nd Jul 2018, 9:05 PM
Janning⭐
Janning⭐ - avatar
+ 1
Hi Skingley Joseph, Welcome! I'm not sure how your statement is relevant to this thread, but if you have a question, you should start your own thread separately so we can help you better.
28th Jul 2018, 2:32 AM
Janning⭐
Janning⭐ - avatar
+ 1
its dont possible un my self
3rd Aug 2018, 11:01 PM
Jean Adou Adou
Jean Adou Adou - avatar
0
you cannot , but you can create classe and id for ex. .myclass{ property:value; } when you refer the css file to your HTML file when you give class to the tag as myclass the properties of the class are given to that tag
8th Sep 2018, 11:54 AM
CHINNEM SUNIL KUMAR
CHINNEM SUNIL KUMAR - avatar