Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
[cssom] getComputedStyle()[--var] return a resolved value? #2358
If you have this...
I know that this...
But I've often found myself needing to find out the resolved value, even if it's not used as the exact value of a property for which I could retrieve the resolved value.
So if the window.innerHeight was
I know there may be more pertinent topics to discuss related to
But the value of
In fact CSS alone can't know that you want to resolve that custom property to a length and not to something else. But the registerProperty Houdini API could be used for that.
Another approach is setting the expression that you want to resolve as a length to some standard property which computes to a length, e.g.
el.style.marginLeft = "calc(50vh + 4em)"; getComputedStyle(el).marginLeft; // 380px el.style.marginLeft = "";
@Loirooriol Your suggested approach is what I often do, and is what I'd meant when saying...
But using that type of approach thrashes my layout more than desired to just retrieve a resolved value.
Didn't think about registerProperty for this, but makes a lot of sense, even if it requires more heavy lifting than my original request.
For anyone else that comes upon this, I figured I would clarify...
If creating the custom property in this way
Will in fact give you a resolved value like