-
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
Extends, nesting and the & combinator. #1554
Comments
I imagine this is because Even if the extend feature would be made to work with your line of code it would generate something like |
I was just about to comment something similar, and that even if that weren't the case I personally would find using the ampersand that way to be counter-intuitive. Keep in mind that directives can be used, like Please feel free to continue the conversation if you want to present additional viewpoints. we can always reopen in the future if we see additional use cases and clarification on the syntax. or @lukeapage might have some perspective to lend as well. |
I think & is just not getting replaced. You could argue it should error, instead it will just never match anything |
@lukeapage are you saying that the |
To be honest i haven't looked at the inner workings of it, i'd say that to determine if .foo.bar is a valid selector the compiler already has to go to the parent scope and check its children. Having been a LESS user for quite some time now the as @lukeapage said: |
I can see where you're coming from. To date, the way that |
Sure @jonschlinkert, no harm done. I was just trying to convey what it felt like as well as the "problem" itself. |
It should probably be open but low priority.. and fixed by either showing an error or making it work, whatever is easier.. I can't see many uses-cases for this? |
The above code could easily be achieved by this:
Even if the ampersand would be changed, doesn't that make you code less readable? |
Sure, but if selector grouping was easy to do or maintain then there wouldn't be much use for the extend feature. Here's a use case:
Currently results in :
It just seemed that,
Would be a "leaner" way to write it. |
Sure, that is leaner, but I don't think it is the right usage of extend. Say for example we got a // Credit: Nicolas Gallagher
.clearfix {
&:before,
&:after {
content: " ";
display: table;
}
&:after {
clear: both;
}
} Before .gallery-list {
.clearfix();
border: 1px solid #afa;
border-radius: 4px;
}
.gallery-item {
float: left;
} The output would include a standalone With extend the output would be much leaner; it would generate the styles specific to So if we'd put this into action: .gallery-list {
&:extend(.clearfix());
border: 1px solid #afa;
border-radius: 4px;
}
.gallery-item {
float: left;
} Would result in the following CSS: .gallery-list {
border: 1px solid #afa;
border-radius: 4px;
}
.gallery-item {
float: left;
}
.clearfix:before,
.gallery-list:before,
.clearfix:after,
.gallery-list:after {
content: " ";
display: table;
}
.clearfix:after,
.gallery-list:after {
clear: both;
} Which is of course a lot shorter than copying all the styles to the gallery-list itself. As for your example, I'd recommend reading up on SMACSS: http://smacss.com or another modular system for CSS. If you have a better example I'd love to discuss this further, I just don't think the given example is the correct usage of |
This is just food for thought, but it will always be difficult or impossible to make decisions based on stylistic preferences. The reason I closed the issue originally is that this can already be achieved using other means, but... that doesn't mean that some users won't get value from a different method or that other use cases won't be exposed once the feature is implemented. I suspect that this is one of those features that will end up giving users interesting workarounds and hacks that no one is thinking of yet... however, all the examples given so far don't necessarily provide any benefit over current methods. So IMHO it boils down to this: out of the ~200 issues, many of which are feature requests for things that would provide transformative unilateral value to Less.js users, which features do you want to cast your vote for? We only have one @lukeapage... |
As i said earlier the only issue i found to be unexpected was that suddenly the & symbol does not do it's magic. Since the & symbol is used as a way of referencing selectors in the inheritance chain it felt weird that the same "shorthand" could not be used to pass selectors as arguments to the extend function. Let's not forget that either CSS or LESS are just tools, so the definition of proper usage depends on the person using it and the objective. @CodingKittens my example is essentially the same usage as Luke Page proposes / demonstrates on his article Extends in LESS, the difference being that i incorporated additional LESS features such as nesting and the & combinator. Your example would be a perfect usage of extends, but unfortunately you cannot pass a parametric mixin (that would simply be the bees knees) as an argument and for the code to work, as you intended, you'll have to use the
results in
I'm currently working on a html / css framework Ink and we use multiple classes to set styling on elements, so my usage of extends would be to minimize if not, completely eliminate duplicate declarations of css properties, which was the basis for my example and seems to be what extend does. |
Also i just found that extend seems to allow a selector to extend itself:
compiles to
|
…ector in extend function arguments.
Hi. I like LESS but... Dont you know is this is an issue in SASS too? Thank you. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hi, and first of all thank you for making and maintaining LESS.
I'm not sure if this is a bug or i'm simply not understanding the intended usage for extends, but i thought that this:
would result in this:
It does not. However writing the full selector as the extend argument works:
I imagined that the & symbol would do the same magic with extends.
And having it not work, seemed really counter-intuitive.
The text was updated successfully, but these errors were encountered: