-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
CSS3 calc() function doesn't work with LESS #974
Comments
👍 |
@rows: 10;
@row1: 1 / @rows * 100%;
.featured1
{
top: ~'-webkit-calc(@{row1} + 20px)';
right: 0;
bottom: @row5;
left: @col9;
} This bit of LESS will process out the value of '@row1' to be 10%, which is great. But when it is inside an escaped seciton of LESS and wrapped in curlys to retain the LESS variable it returns '10' without the '%'. I've found a workaround that hasn't failed me yet. If you place another '%' after the closing curly of the 'row1' variable inside the escaped code it will work correctly... ~'-webkit-calc(@{row1}% + 20px)'; But that seems like quite a hack to add in another unit type that is suppose to already be in the variable. |
@jonjohnjohnson this is fixed in head and will be in 1.3.2 the rest of this bug will be resolved in 1.4.0 |
Not sure if this is the same issue, but I'm having a problem with the following. Note there's no less-specific stuff here, less 1.3.3 is munging otherwise valid CSS. Here's the CSS html, body {
margin:0, padding:0, border:0;
height: 100%;
}
#content {
height: -webkit-calc(100% - 40px);
height: calc(100% - 40px);
background-color:gray;
}
#footer {
background-color:black;
} And here's the HTML to include it <!doctype html>
<html lang="en">
<head>
<link rel="stylesheet/less" type="text/css" href="test.css" />
<script src="less-1.3.3.min.js"></script>
<body>
<div id="content"></div>
<div id="footer" style="height:40px"></div>
</body>
</html> "content" is being set to a height of 60%, so less is parsing & incorrectly resolving the calc expression rather than passing it unchanged through to the browser. Tested in Safari 6.0.2 and Firefox. |
Fixed on master for 1.4.0 |
height: ~"calc(100% - 50px)"; still produces: height: calc(50%); for me. I want: height: calc(100% - 50px); |
What’s more, it still produces |
@OliverJAsh I can't reproduce your results with Less 1.7.0 (both escaped value and |
I was having this issue in 1.6.3 (for some reason, WinLESS is barfing on compile when I upgrade to 1.7.x, so I'm sticking to 1.6.x for now) My quickfix was just to escape one part of the equation like:
This even works for variables, like |
@twiginteractive If you have to use escaping with |
@seven-phases-max Hmmm - according to the docs, with SM off (default) then this should get parsed correctly (i.e. untouched) But it doesn't. The output CSS is (Unless I am mis-reading the docs when it says "will be processed correctly"... LESS couldn't know the value of 100%, so it shouldn't do a mathematical computation on '100% - 10px') |
No, the word there is |
@seven-phases-max Ah - my bad, it makes sense now. Thanks for the clarification. |
height: ~"calc(100% - 50px)"; Worked for me. |
height: _calc(50%);
height: calc(100% - 50%); /* browser-native */ |
This won't affect |
P.s. the solution to this problem is strict maths. And maybe we should |
|
Why? Does myth remove parentheses? Strict math makes less a proper superset |
Example? I.e. a snippet where Less screws an expression inside |
Since when will v2 prefix functions? Did we decide that and I forgot? |
No. I guess this was just slightly overestimated #2102 (comment). |
Yes, sorry, not "the option to" but "the ability write a plugin providing the option to". |
In a UIkit 3 theme I am using this in
And it works. |
It worked for me when writing in *.less file #974 (comment) Thank @lukeapage ! 🥇 |
Hi @mqliutie thanks for adding the mixin suggestion for calc, but, there is an extra ~ in your Mixin that was breaking the compilation: the mixin should be
Input as follows: Output as follows: |
Why is this issue closed?! It's not fixed. I'm still getting Please reopen this issue. |
@thany |
@jonjohnjohnson That's just stating the problem again. If strict mode fixes it (haven't tried yet, shouldn't be neccesary to enable all kinds of nondefault flags in order to work around bugs) then it should be on by default. No matter how you put it, this issue is not fixed by any definition. |
@thany I was just trying to help you understand that the developers decided it's not an issue according to them. Those comments don't just restate the problem, they describe the developers stance on the issue. Good luck. |
It can't be because this would immediately break zillion projects out there. So if you treat the default behaviour as an issue just set the documented option and be done. By any definition.
Because the uptodate disscussion of how to improve the default behaviour is here. |
@thany As @seven-phases-max, if you want to see this solved, contribute to #1880. I think the solution is there, but there hasn't been enough community weigh-in to come to a decision that is ready to implement. It's a long thread, but that's what solution-finding takes: reviewing proposals and weighing in one way or another. And then: someone to take on the work to implement. |
* calc() fix - fixes #974 * Parses and retrieves a namespaced value * Adds a bunch of new tests for aliasing and namespacing * Added more CSS Grid tests * Added tests for passing mixins into mixins, since it's just another value * Release v3.5.0-beta.4
width: 15%;
height: ~"calc(width)"; how to make height=width |
@xiaomizhou66 |
So this is still broken. calc(100vh - 138px) comes out to -38px. |
If you expirience this problem with Less 3.x, please create a separate bug report. |
== Less_Tree_Operation == In Less_Tree_Operation::operate(), we call Dimension::operate() with argument $b (named $other there), which Dimension expects to be a number with a unit, i.e. something we can perform math on. Change Operation::operate() to not call this if argument $b is something else, which avoids the reported PHP warning of $other->unit being undefined. Noting that the only class with a 'unit' property is Less_Tree_Dimension. As a side-effect, this immediately fixes another bug, namely that the "var()" right-hand side of `calc(100% - var(foo))` was completely ignored previously when it wasn't a number. For example, it can be a CSS keyword or CSS function like var() that the browser handles client-side. Noting that CSS also natively supports math. LESS should only handle math when the input uses PHP variables or literals, and thus effectively has a constant outcome. Previously, Dimention::operate() would implicitly read $other->value as NULL when $other value wasn't a numerical Dimension object, and thus the math operation silently failed before this commit, e.g.: > "100% - var(foo)" > "100 - NULL" (as %) > "100%" With the warning avoided/fixed, we now correctly preserve the equation in its entirely when $b is e.g. a var() call. == Less_Tree_Call == The above change on its own is insufficient, as that elevates the warning to a fatal error. The added test case exposes this, where `calc(100% - var(foo) - var(bar))` is parsed as: Call (calc) \-- Expression \-- Operation (-) |-- Operation (-_ | |- Dimension (100%) | |- Call (var foo) |-- Call (var bar) The above change, makes the first Operation pair no longer compile Dimension+Call down to a Dimension, instead preserving Operation as literal CSS output. This means the second Operation will now see a left-hand value of Operation, which doesn't have an "operate" method, and thus correctly triggers the `throw` statement that I cleaned up, because that's not something we can compute server-side. Fix this by recognising `calc()` higher up as something that server-side LESS math should not be performed on in the first place. This effectively backports less/less.js#3162 (less/less.js@a48c24c4dd3c13e00a20ece803237) for the similarly reported issue upstream at less/less.js#974. That bugfix was originally released with less.js 3.0.0, but the part of that I'm backporting here doesn't change behaviour of any of our less.js 2.5.3 compliance tests, thus safe to backport. We already threw a fatal error when one of the arguments wasn't a Dimension or Color (no other class has the 'operate' method), so this only adds non-fatal outcomes to previously fatal outcomes. Bug: T331688 Change-Id: Idd443a76372682de4edddeb64ab5a65b23bbd3ce
I know it's been reported already but bugs were closed due to insufficient information.
I have the following CSS code:
I wanted to transform it into LESS using
130px
as a parameter but calc gets internpreted by LESS and this:makes the last but one line transformed to
width: calc(-30%);
which is clearly not what's desired. I tried usingwidth: ~"calc(100% - @id1width)";
but it makes@id1width
not interpreted.I think LESS shouldn't use things reserved by CSS3 for its internal use...
The text was updated successfully, but these errors were encountered: