-2

//style.sass

$common-color: #333;

body {
  font: 100% $font-stack;
  color: $common-color;
}

can I do the similar in css? because I am not using .sass for my project.

1

3 Answers 3

1
:root {
    --maincolor: red;
    --mainfont: Arial;
}

body {
   color: var(--maincolor);
   font: var(--mainfont);
{
Sign up to request clarification or add additional context in comments.

Comments

1

You can write it as below

:root {
  --common-color: #333;
}

body {
  font: 100% $font-stack;
  color: var(--common-color);
}

Here :root is the scope of the variable

More information can be found in the link - https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties

Comments

1

In CSS3 you're able to use variables by declaring them with --name-of-variable and access them with var(--name-of-variable). Your example would look like:

:root {
  --common-color: #333;
  --font-stack: 'Roboto', sans-serif;
}

body {
  font: 100% var(--font-stack);
  color: var(--common-color);
}

See https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties for more information about scoping and fallbacks.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.