G
G
grabbee2017-08-28 17:38:56
css
grabbee, 2017-08-28 17:38:56

How to inherit class properties in LESS with nesting?

Is it possible to simultaneously inherit parent properties with nesting?

.link {
  cursor: pointer;
  text-decoration: none;
  &-primary {
    color: red;
  }
}

So that at the output both the link and link-primary classes contain properties
cursor: pointer;
text-decoration: none;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton fon Faust, 2017-08-28
@grabbee

Right off the bat, solved by using mixins

.op {
    cursor: pointer;
    text-decoration: none;
}

.link {
    .op;
    &-primary {
        color: red;
        .op;
    }
}

Or with extend :
.link {
  cursor: pointer;
  text-decoration: none;
  &-primary:extend(.link) {
    color: red;
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question