-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unitless values eg for "ew" values #12
Comments
Howdy Toby! I see what you mean, here's the code for // Element width units
case 'ew':
return elements[j].offsetWidth / 100 * $1 + 'px'
break So you should be able to use the same formulas directly in any EQCSS query with The formulas would be:
The numbers that @element div {
:self {
font-size: calc(10px * eval('offsetWidth / 100'));
}
} |
Thanks Tom! That's a great option for now. Also, perhaps it's something to consider to add this to the CSS API (so that EQCSS users can get unitless values without having to use eval/JS). |
I'm not sure what you mean when you say:
The feature definitely uses JS to arrive at the number I don't think having a shorthand like I've experimented with unitless values for switch(unit) {
case 'ew':
return tag.offsetWidth / 100 * number + 'px'
case 'eh':
return tag.offsetHeight / 100 * number + 'px'
case 'emin':
return Math.min(tag.offsetWidth, tag.offsetHeight) / 100 * number + 'px'
case 'emax':
return Math.max(tag.offsetWidth, tag.offsetHeight) / 100 * number + 'px'
} |
Adding this as option to the proto-CSS-API of EQCSS could look like this:
It would be an addition to the API which would allow devs to get the unitless value without using eval(). It's just an idea, that's all - eval is OK enough 😀 Anything can be done in eval, and anything can be done in JS - the latter would mean I'd write my JS and not use EQCSS 😀 So I'm generally happy if my CSS stays pure CSS / proto-CSS / non-JS. But small exceptions using eval are OK enough. |
One thing I just spotted in the wild this week is some code that uses an external function to calculate numbers: https://www.freedomfirstsociety.org In the source code of the website you'll see this EQCSS code: @element #b-trail {
$this {
padding-top: eval("trailFunc2()");
padding-bottom: eval("trailFunc2()");
}
} It calls the var trailFunc2 = function() {
var x = document.getElementById("img-responsive").clientHeight;
var y = document.getElementById("trail1").clientHeight;
var z = (Math.max((x - y), 0)/2) +"px";
return z;
}; This is one way you can include complex JS-based math calculations to supply values, use #b-trail {
padding-top: var(--trailFunc2);
padding-bottom: var(--trailFunc2);
} |
I had a case where I wanted to use an "ew" value as a multiplier, but that resulted in an invalid calc() expression:
https://bugs.chromium.org/p/chromium/issues/detail?id=813325
Is it possible to ask EQCSS for a unit-less value? (eg like "ew" but without a unit, or just any value based on element width without a unit, for use as a multiplier)
The text was updated successfully, but these errors were encountered: