Skip to content

Instantly share code, notes, and snippets.

@taxigy
Created April 21, 2017 09:53
Show Gist options
  • Save taxigy/c4e2a165c5a5ab8df996e2c700d92c33 to your computer and use it in GitHub Desktop.
Save taxigy/c4e2a165c5a5ab8df996e2c700d92c33 to your computer and use it in GitHub Desktop.
Variables in CSS styles
/* ONE: nested media query and calc */
:root {
--value: 30px;
}
.element {
border-radius: var(--value);
@media (min-width: 768px) {
border-radius: calc(var(--value) * 2);
}
}
/* TWO: redefining variable against media query separately from style declarations */
:root {
--value: 30px;
}
@media (min-width: 768px) {
--value: 60px;
}
.element {
border-radius: var(--value);
}
@jmak
Copy link

jmak commented Apr 21, 2017

In Pure CSS second example doesn't work but after small modification the following works fine.

:root {
  --value: 30px;
}

@media (min-width: 768px) {
  :root {
    --value: 60px;
  }

  /*  OR 
  .element {
    --value: 60px;
  }
  */
}

.element {
  border-radius: var(--value);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment