-
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
parent selector ala SASS #127
Comments
Referring to the .clearfix example in the Wiki, I guess it is already supported: You can also bundle pseudo-selectors with your mixins using this method. Here's the classic clearfix hack, rewritten as a mixin (& represents the current selector parent): .clearfix {
} |
Yes that works in less.js, but lets take the example where you dynamically add classes on the html or body element (serverside or with js) referring to the user agent such as .ie ie6 .ie7 .mozilla etc... So your html looks like: <html class="ie6"> And now in your css you can target styles only for say ie6 like this: .ie6 button { ... } So now say have a mixin for buttons and I want that conditional for ie to be in it: .mixin { ... &:hover { ... } .ie6 & { // Fix for ie6 } } This is supported in SASS and I read somewhere this is planned for lesscss, perhaps in dotless (lesscss for .NET) So is this planned? Should I try to take a stab at it and try to implement it? Thanks |
This would be awesome for things like Modernizr. +1 |
This would be very very useful for things like Modernizr. I would prefer some other syntax though, but that might just be me.. |
Yes please! |
+1 |
The proposed syntax in #251 is the best I can imagine for this. ~Ross |
@rosshadden i don't think #251 is suggesting that
compiles to a {
font-weight: bold;
}
a:hover {
text-decoration: underline;
}
.selector a {
font-weight: normal;
} |
@neonstalwart: I understand, thank you for your clarification. You are right, I was greatly limiting the capabilities by my assumption! Now the syntax proposed in this issue makes more sense than the one in #251, and fits better with the existing LESS syntax. ~Ross |
I'm fine with either syntax: "[.selector]" or ".selector &". I guess the brackets might cause confusion because they can be used to select attributes in regular CSS. Has anyone implemented this? |
+1 for |
One thing I can't see is how it would handle this code:
Where I would like that to render as:
Should the "&" return all parents? That is not how "&" works today, right? |
I would be least surprised if this:
Expanded to this:
Or, in other words, just like |
An alternative might be to prepend some character to Maybe that could be
OR perhaps use |
It looks like SASS uses
If we use it some other way, we should prob'ly use some other symbol... |
Was about to request the same feature. Mordernizr.js and HTML5 Boilerplate both have awesome CSS3 and Internet Explorer detection tricks that rely on classes added to the html tag. If this feature would be implemented it would greatly reduce the amount of LESS CSS I'd have to write ànd improve the legibility/portability of my code. +1 |
I too am constantly finding the need for this feature for the reasons mentioned by gillesv. I really hope this gets in. It just feels messy and somehow disappointing to create a nice self-contained nested block of LESS to describe a module and then have to create a separate block for when that module is a child of an alternative ancestor. +1 |
This is one of the first issues I raised on this project #9 I'd love to see this implemented. +1 |
Ok. So I've implemented it in dotless here https://github.com/dotless/dotless/tree/commit/468e650c it was quite straight forward so should be easy enough for someone to back port into less.js Have fun :) |
Ok. So I just ported this over to less.js, here's the pull request. Enjoy. |
Thank you! |
So in sass you can use the parent select as such:
which is compiled to:
Is this planned for less.js?
The text was updated successfully, but these errors were encountered: