-
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 dynamically-generated selectors #1539
Comments
Most likely related to #1196. A workaround for the future is to build the mixin to a separate, temporary stylesheet and then include it as a reference import. First, build @min-font-size: 8px;
@base-font-size: 16px;
._t {
.step(@font-size) when (@font-size > @min-font-size) {
&-@{font-size} {
font-size: unit((@font-size / @base-font-size), rem);
.no-cssremunit & {
font-size: @font-size;
}
}
.step((@font-size - 1));
}
.step(11px);
} Then, build @import (reference) "type.less";
.box {
&:extend(._t-9px all);
} Outputs: ._t-11px { font-size: 0.6875rem; }
.no-cssremunit ._t-11px { font-size: 11px; }
._t-10px { font-size: 0.625rem; }
.no-cssremunit ._t-10px { font-size: 10px; }
._t-9px { font-size: 0.5625rem; }
.no-cssremunit ._t-9px { font-size: 9px; } ._t-9px,
.box {
font-size: 0.5625rem;
}
.no-cssremunit ._t-9px,
.no-cssremunit .box {
font-size: 9px;
} The problem of course is that two separate stylesheets need to be built. It works, but I'd like to avoid a build script dependency. What if reference-type |
+1 Another useful case where this comes up is when generating grid system classes. Ideally, you should be able to use the grid classes directly in your html or extend them in your LESS. I've been working on porting over the Foundation 4 grid to LESS and it works well, except I can't extend the grid classes. I can use a mixin instead, but it will result in a ton of repeated code. A simplified example of how I'd like it to work:
This should ideally make the .my-classname class show up with the small-3 and medium-5 classes within their respective media queries. |
👍 to this. Currently working on a project using FontAwesome and it would be great to be able to extend their |
Just in case for the FA there's "FA specific" workaround (the second example). |
Great! I worked around it like so, should anyone stumble on this: // Font Awesome helper
.icon() {
display: inline-block;
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon(@icon) {
&:before{
@fa-icon: "fa-var-@{icon}";
content: @@fa-icon;
}
} Unfortunately I had to repeat the styles of the |
^ I'm just trying to slightly sort all these "extend dynamically generated selector" issues by adding a bit more specific names to them (the problem is that most of such tickets cover 2-3 quite unrelated |
@seven-phases-max I wanted to fix it in a general way - if a selector includes interpolation, attempt re-parsing it. I haven't given it a go yet though. Was thinking to pull selector parsing into its own class. |
@lukeapage OK, I was just thinking of maybe merging all these into one issue with minimal and simplified example for each "sub-issue" for easier tracking. But probably it's not worth that (yet at least). |
Great, sounds good, didn't mean to sound anti what you were doing, was just |
Merging to #2200. |
Hi,
I'd like to have a recursive mixin that generates step classes, which can be used for extends.
Here's an example. For now, let's disregard that the
._t-
-prefixed classes get output in the compiled CSS (that's for another ticket).Here's what I'd like it to output:
Here's what it actually outputs:
The issue depends on #1177 and probably a few others - of course I don't want every selector between
._t-140px
and._t-8px
but if mixins could be extended, I wouldn't have a problem with writing the font classes manually (which would prevent them from being output in the generated CSS).Any thoughts on the best way to implement a system like this, or should I adjust my approach?
The text was updated successfully, but these errors were encountered: