Skip to content
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

Allow for pseudo-classes to be used as mixins #1630

Closed
lencinhaus opened this issue Nov 1, 2013 · 4 comments
Closed

Allow for pseudo-classes to be used as mixins #1630

lencinhaus opened this issue Nov 1, 2013 · 4 comments

Comments

@lencinhaus
Copy link

This would be particularly useful when importing an external less library that defines rules on pseudo-classes, an you want to mixin those rules in another class that will be applied to an element that doesn't support the pseudo-class.
See the following example to understand what I mean:

.class {
  rule: something;
  &:focus {
    color: red;
  }
}

.otherclass {
  .class:focus;
}

should compile to:

.class {
  rule: something;
}

.class:focus {
  color: red;
}

.otherclass {
  color: red;
}

I've happened to need this while working with Bootstrap 3: I was trying to mix in the rules from .form-element:focus into another class that I wanted to apply to a div, which doesn't support the :focus pseudo-class. So, I ended up manually copying all the rules from the bootstrap pseudo-class into my other class, which is a really poor solution in a less-based project.

@10xLaCroixDrinker
Copy link

👍

@seven-phases-max
Copy link
Member

See #1048, #1395. The Extend feature gives the best fit for this task.

@SomMeri
Copy link
Member

SomMeri commented Nov 2, 2013

An example how to use extend to solve your problem with the extend keyword.

If you do this:

.class {
  rule: something;
  &:focus {
    color: red;
  }
}

.otherclass:extend(.class:focus) {
}

then less.js will add #b selector into all rulesets with #a a selector:

.class {
  rule: something;
}
.class:focus,
.otherclass {
  color: red;
}

I will close this as a duplicate, because the issue #1048 covers the same problem. If you think that extend does not solve your problem, feel free to make your case there. The feature is more likely to be added if we known about something that is not possible to achieve without it.

@SomMeri SomMeri closed this as completed Nov 2, 2013
@lencinhaus
Copy link
Author

Thank you for your answer.
I had already tried :extend before posting this, but I was getting a syntax error during compilation: it turns out that my problem was due to Meteor shipping with an old version of less (1.3.3) that doesn't support the :extend clause. I'll ask them to bump their less version to 1.4+.
Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants