I am trying to have CSS variables for box model properties. I want to support both setting a value for all sides as well as individual sides. I want to have default values, but be override-able either way.
I tries using fallback values, but with little success.
Something like:
:root {
--border-width-top: 0;
--border-width-right: 0;
--border-width-bottom: 0;
--border-width-left: 0;
--border-width: 0;
}
div {
border-color: red;
border-style: solid;
border-width: var(--border-width, var(--border-width-top) var(--border-width-right) var(--border-width-bottom) var(--border-width-left));
}
div {
--border-width-top: 10px;
}
This will not work as if border-width has a default value then it will always take precedence over the fallback values.
Not sure there is a way to do this currently, but I feel so close to finding a solution.
Here is a stackblitz I am playing with: stackblitz
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…