I want to give a CSS variable the value unset, so I can use it for things like outline: unset
. (I am aware that the "unset" in --unset-it: unset
refers to the variable itself.)
Can it be done? I have made some test here:
const theDump = document.getElementById("dump");
const root = document.documentElement;
let checked = false;
document.getElementsByName("unset-it").forEach((elt) => {
function displayIt(elt) {
root.style.setProperty("--unset-it", elt.value);
const propVal = getComputedStyle(root).getPropertyValue("--unset-it");
theDump.textContent = `--unset-it: ${propVal};`;
}
if (!checked) {
checked = true;
elt.checked = true;
elt.focus();
displayIt(elt);
}
elt.addEventListener("click", evt => {
const elt = evt.target;
displayIt(elt);
});
});
* {
box-sizing: border-box;
}
#ex {
background: yellow;
padding: 0.5rem;
margin: 1rem 0;
}
input[type=radio] {
position: relative;
width: 15rem;
margin: 0;
margin-left: 1rem;
margin-bottom: 0.5rem;
}
input[type=radio]::after {
content: attr(value);
position: absolute;
left: 0;
top: 0;
}
#div1 {
outline: var(--unset-it, 2px dotted red);
}
<input type="radio" name="unset-it" value='"unset"'>
<input type="radio" name="unset-it" value="'unset'">
<input type="radio" name="unset-it" value='unset'>
<input type="radio" name="unset-it" value='whatever'>
<input type="radio" name="unset-it" value='"whatever"'>
<input type="radio" name="unset-it" value='5px solid green'>
<input type="radio" name="unset-it" value='"5px solid green"'>
<input type="radio" name="unset-it" value="initial">
<div id="ex">
<p id="div1">
outline: var(--unset-it, 2px dotted red);
</p>
<p id="dump">Dump</p>
</div>