-
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
Extend does not assume nested selectors #1730
Comments
You need to use the
|
hey @Soviut, I guess it doesn't work on this case because |
Actually, you should be extending |
@jonschlinkert I am taking into consideration that on the first example |
No, in your first example you're doing Expanded out, you have: body div {
color: red;
}
body {
p:extend(div) {
background-color: green;
}
} So you need to do: body div {
color: red;
}
body {
p:extend(body div) {
background-color: green;
}
} |
I believe it does matter body {
div { color: red; } /*selectors are compiled to `body div`*/
p { border: 1px solid red; } /*selectors are compiled to `body p`*/
p:extend(div) { background-color: green; } /*while `body p` is transposed ok why `div` is not translated to `body div` *automatically? it should because it is all inside `body`*/
} Also on my first example the code is almost the same as above and it is all nested within |
I do understand what you mean, you're expecting to be able to "shortcut" over to a selector that is nested inside the same block. and I can see why that might seem appealing. But LESS actually doesn't work that way anywhere else. Selectors are still specified the same way they are in CSS, regardless of being nested together. This isn't exactly the same, but it might help with the logic. Consider objects and properties in JavaScript. You can't do this: var obj = {
foo: 'one',
bar: foo
}; But you can do |
Does this applies for LESS command line interface as well? Perhaps I am now getting what you are trying to say. Which is: If that is the case, then I now can understand why it will never find |
I'm just saying you need to specify the selector you want to extend. Nothing more. |
@jonschlinkert thanks man. I have assumed that on my question, but just wasn't sure why this was happening. |
I wouldn't want to change the current behaviour as its a breaking change. also forcing the current selector into what you are extending restricts what you are allowed to extend.. where as at the moment it is flexible, though in this usecase you have to repeat the parent selector.. |
@lukeapage what happens in the case of the following example tho? I am not sure if that is as flexible as you have mentioned.
Please note that there is no way to extend anything inside a |
This is how it is supposed to be just by definition of the
is just a shortcut for:
How can we inject any P.S. Probably some kind of warning (again?! :) would be handy when an |
Btw, I'm not on re-opening this issue but I think I have an argument to support the initial example. I guess this issue is a bit wider than it seems to be, it can be re-phrased to "Should extend respect its scope or should it not?" :)
A one (not yet familiar with how
In general both ways make their sense (but I know that implementing "current scope aware extend" would be quite non-trivial so there's no real choice). For us the confusion may be not so evident just because we already know how exactly it works. Perhaps we could mention this in the docs? E.g. "extend is not current scope aware" or something? (I don't know what would be the best way to say this: "a:extend(b) never considers 'b' scope to be relative to the 'a' scope". I.e. similar to 'relative path' vs. 'absolute path': |
@seven-phases-max that's sounds a good idea. I am in favour because for me, knowing a little bit of LESS mostly because of its nested selectors feature. This got me by surprise and let me a bit confused. |
Lets put it in the docs. As I said, scope aware extend would screw over this more normal case
We could support & in the extend argument, e.g.
but I'm not sure its worth it if people just understand its an absolute selector. Re-open this if you think its worth implementing something like this. |
I have to say I would have expected the same behavior as @zanona. I didn't know this before, but I think it is a major drawback that I can't use E.g. take this
and compile to
|
media queries are a whole different issue |
I guess the proposal behind I guess in a way, As @seven-phases-max mentioned: it is easy for the folks behind the project to see it through because they are used with how things work in the backend. So as for I may have got the wrong impression with this and I am sorry if I did, but for me it seems |
This issue specifically the case in the description will not be changed.. Media queries are in a different bug and we understand its a shortcoming |
I disagree that it's misleading, since it's consistent with how selectors work in general, but I think there is merit to what you're suggesting. So how about if we reopen this as a feature request for having "scoped selectors" work similarly to scoped variables in mixins? @lukeapage? |
Btw., just in case, using
I.e. if |
IIRC, the interpretation of what selectors actually are was one of the contention points when we were developing the That is, in @zanona's example:
That's not to say anything should change about it, especially after how much debate it went through, just to illustrate that we've always had developers think about their Less code in basically two different ways. If you like an evening of reading, you can check out Issue #1155. Ultimately, we went with the simplest, most pragmatic approach to As far as extend not working inside of @media, I thought that was resolved per #1165 ? |
No, it's considered as expected and documented behaviour ( |
It seems the feature “Extend” does not assume nested selectors:
This doesn't work
This does work
This also does work
please notice that I had to declare
body div
on the second example for the feature to work where it should assume its inheritance automatically and the first example should work without problem, but unfortunately that doesn't happen.The text was updated successfully, but these errors were encountered: