-
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
LESS own syntax for Custom Properties #2968
Comments
This conflicts with (or closely matches) property referencing syntax, which is already added to the Less 3.0 development branch. As of Less 3.0, you can write it like: .element {
color: #ff92ea;
@color2: #22adf2;
border: 2px solid $color;
background: linear-gradient($color, white, @color2, yellow);
} |
Excuse me, may I request a quick summary on |
Basically the .element {
color: #ff92ea;
border: 2px solid $color;
} results in: .element {
color: #ff92ea;
border: 2px solid #ff92ea;
} Another way to understand it is that properties in 3.0 are basically being treated like variables, except that the property will be in the resulting output. This is similar in Less to how simple class and id selectors are also mixins. That is: The only difference is that the simple selector definition without parentheses will be in the resulting output. So, in Less 3.0, similar to how selectors can be used as mixins, properties can be used as variables. As far as using any custom Less syntax to output custom property syntax, I'm not sure it would be a good fit. For another thing, you're only saving yourself one or two characters. That's not to say you couldn't do it at all with Less. You could always do something like: .-(@prop, @var) {
--@{prop}: @var;
}
.element {
.-(my-font; Awesome Font);
} produces: .element {
--my-font: Awesome Font;
} But.... I don't understand why someone would ever want to do that. Seems pretty pointless just because you don't like a certain syntax in CSS. |
Veeery interesting– Thank you very buch for this highly detailed explenation. I appreciate it. Although I see your point, that my request would interfere with 3.0s new property handling, I disagree with your saying that I only save a few characters. Especially calling vars is a mess to write AND read.
Anyhow. Where can I read more about this mixin-style-property-feature? I have a lot of questions regarding this concept. |
Speaking of the proposal itself, two remarks:
--my-font: Awesome; /* custom value */
p {
font-family: var(--my-font, Robot /* fallback value */);
}
div {
font-family: var(--my-font, Robot /* fallback value */);
} and the same using typical Less implementation: @my-font: Robot; // fallback value
p {
font-family: @my-font;
}
div {
font-family: @my-font;
}
@my-font: Awesome; // custom value (I intentionally use the variable twice to illustrate that in many use-cases the existing Less way is actually more compact and more easy to maintain). Aside of above I see no problem for the function (not necessary tied to |
Less throws parse exception if I add the CSS custom properties. Does LESS supports CSS custom properties? |
@Hakuz As a general principle, yes, with some caveats. Are you using the latest version of Less, and what's the content of your custom property? |
I really do not like the syntax of custom properties and I want to suggest a simple "search&replace" solution for a preprocessor. (At least my layperson mind things it's ez to implement :O)
actual syntax
my suggestion
or
The idea put in words:
Declaration =
$
1 DollarUsage =
$$
2 Dollars OR$()
1 Dollar + parenthesis (maybe use 2 here aswell for consistency?)LESS then compiles to actual custom property syntax
PROS
– Much easier to write and read
– The
$
is easy to distinguish from the LESS-var@
.– Developers are used to the
$
from jQuery and PHP– Sass users will we confused 😎
CONS:
– Sass users will be confused 😭
What do you say?
PS:
please assign "Suggestion" / "Feature Request" label; I am not allowed to :(
The text was updated successfully, but these errors were encountered: