1

I am fairly new Less and have been trying to get a jQuery plugin to work with my custom CSS generated via Less. Basically, what I have is the following html generated by a plugin:

 <div class="classA class B" ....>
      <div class="classC classD"  ....>
           <div class="classE classF" ....>
           ..........

I am not sure how to structure my Less file in order to generate CSS that matches the above.

I have tried:

     .classA {
       ......
        &.classB  {
          .....
              &.classC {

               ....and so on

but it generates the following CSS:

.classA {...}
.classA.classB {....} /*This does not include the CSS of classA */
.classA.classB.classC {.....} /*This does not include CSS of classA or classB*/
 ...

The plain CSS is fairly easy to write :

 .classA {.....}
 .classB {.....}

and when I write how do I achieve the above using Less? Is there a simple way to achieve this without using functions or extends?

1
  • 1
    That's what & does in less. If you want the output to be .classA {.....} .classB {.....} don't use &. The "plain CSS" will work in less. Commented Mar 8, 2015 at 21:27

2 Answers 2

2

Nesting elements in less has the result you're describing when adding the & : you specify the selector that uniquely matches with that parent and child class (.classA.classB in CSS ),

to do what you're asking

  .classA {.....}
  .classB {.....}

you simply shouldn't nest_

Sign up to request clarification or add additional context in comments.

Comments

1

If your goal is to inherit styles of one class by another one, you can use mixins:

.foo() {
    background: #ccc;
}

.bar {
    .foo;
    color: #000;
}

Output CSS:

.bar {
    background: #ccc;
    color: #000;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.