Skip to content

Instantly share code, notes, and snippets.

@gregwhitworth
gregwhitworth / custom-props-valid-prop.css
Created February 28, 2017 01:46
custom-props-valid-prop.css
--bg: rgb(calc(var(--r) + var(--modifier)), calc(var(--g) + var(--modifier)), calc(var(--b) + (var(--modifier) + 50)));
@gregwhitworth
gregwhitworth / custom-props-get-prop-value.js
Created February 28, 2017 01:39
custom-props-get-prop.js
var myComponent = document.getElementsByClassName('my-component')[0];
var cs = getComputedStyle(myComponent);
cs.getPropertyValue('--primary');
@gregwhitworth
gregwhitworth / custom-props-set-property.js
Created February 28, 2017 01:34
custom-props-set-property.js
var myComponent = document.getElementsByClassName('my-component')[0];
myComponent.style.setProperty('--primary', 'green');
@gregwhitworth
gregwhitworth / custom-props-scoping.css
Created February 28, 2017 00:25
custom-props-scoping.css
body {
--primary: blue;
background: var(--primary);
}
.my-component {
--primary: yellow;
background: var(--primary);
}
@gregwhitworth
gregwhitworth / custom-props-animate.css
Created February 27, 2017 23:57
custom-props-animate.css
div {
--pos: 0;
left: var(--pos);
animation: move 1s;
}
@keyframes move {
to {
--pos: 50px;
}
@gregwhitworth
gregwhitworth / custom-props-feature-detection-2.css
Created February 27, 2017 23:30
custom-props-feature-detection-2.css
:root {
--foo: true;
}
body {
background: red;
}
@supports(--foo: false) {
body {
@gregwhitworth
gregwhitworth / custom-props-feature-detection.css
Last active March 17, 2017 17:32
custom-props-feature-detection.css
body {
background: red;
}
@supports(--foo: blue) {
body {
background: green;
}
}
div {
--primary: blue;
margin-top: var(--primary, 12px);
}
@gregwhitworth
gregwhitworth / custom-props-fallback.css
Created November 16, 2016 01:55
Custom properties with a fallback value
body {
background: var(--primary, blue);
}
@gregwhitworth
gregwhitworth / custom-props-basic.css
Created November 16, 2016 01:25
A basic overview of custom properties
:root {
--primary: #0B61A4;
--secondary: #25567B;
}
header {
background: var(--primary);
border-bottom: 2px solid var(--secondary);
}