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

Add feature to use base class #1709

Closed
jaanush opened this issue Dec 3, 2013 · 9 comments
Closed

Add feature to use base class #1709

jaanush opened this issue Dec 3, 2013 · 9 comments

Comments

@jaanush
Copy link

jaanush commented Dec 3, 2013

Sometimes it is usefull to have a base-class to put all your stuff into. This makes it easy to avoid conflicts with other elements on the page that are out of your control.

Most of the time you can just wrap your less code in a wrapper class but the reversed nesting with & breaks this approach.

.bs3 {
    .form-control {
        height: 34px;
        textarea& {
            height: auto;
        }
    }
}

becomes

.bs3 .form-control{
    height: 34px;
}

textarea.bs3 .form-control {
   height: auto;
}

which totally breaks the intended behaviour.

The only two approaches I can think of is to either append the wrapper class in the compiler or add a depth parameter to the reverse nesting.

@Soviut
Copy link

Soviut commented Dec 3, 2013

Why are you using the & symbol that way? Why not just use normal nesting?

.bs3 {
    .form-control {
        height: 34px;
        textarea {
            height: auto;
        }
    }
}

Regardless, a "parent depth" has been discussed in other issues. #1075

@jaanush
Copy link
Author

jaanush commented Dec 3, 2013

That would not work since the textarea is not a child of the .form-control element but I understand where you are heading.

In this case it's not me using reverse nesting. What I'm doing is putting bootstrap in a wrapper class. They are using reverse nesting. The quick(er) fix would of course be to make them stop using it but I chose to post it here since I perceive this as a shortcoming of lesscss.

@seven-phases-max
Copy link
Member

@jaanush, I suspect what you name a "base class" is simply a "namespace" (more details here), though to give some examples of using namespaces for your use-case we need to know how exactly .form-control is planned to be used.

I remember very similar discussion at stackoverflow recently, there's a solution if you simply need to prepend all bootstrap selectors with some extra class/id:

.namespace-bs {
    @import (less) "css/bootstrap.css";
}

@jaanush
Copy link
Author

jaanush commented Dec 4, 2013

Yes, that is exactly what I do with the . bs3 class but I chose not to call it namespace since that's something a bit different.

If you look at my original example you can se how the reversed nesting prepends the textarea element to te "namespace" so it becomes textarea.bs3. This behavior breaks your example.

@seven-phases-max
Copy link
Member

This behavior breaks your example.

No, it does not. This solution is not the same as you have already tried. Notice the extension of the imported file and (less) modifier.

@jaanush
Copy link
Author

jaanush commented Dec 11, 2013

Sorry, missed that small distinction. That looks like it should work

@lukeapage
Copy link
Member

tbh I'm a bit lost now.. can this be closed?

@seven-phases-max
Copy link
Member

I think it can be closed (since there's no way to "fix" it and in the rest it is a sort of #1075 variation)

@jonschlinkert
Copy link
Contributor

done

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

No branches or pull requests

5 participants