Add a Parent '&' to a variable using LESS

Asked

Viewed 13 times

2

I have a problem but I do not know if it is possible, I’m wanting to edit some class putting a & follow the example:

.bcolor(@prefix, @suffix) {
    .@{prefix}red@{suffix} {
        background-color: red;
    }
    .@{prefix}blue@{suffix} {
        background-color: blue;
    }
}

table {
  &.bcolor {
    .bcolor(bc-, ~">tbody>tr");
  }
}

All right here but the answer is this:

table.bcolor .bc-red>tbody>tr {
  background-color: red;
}
table.bcolor .bc-blue>tbody>tr {
  background-color: blue;
}

I would need that answer so:

table.bcolor.bc-red>tbody>tr {
  background-color: red;
}
table.bcolor.bc-blue>tbody>tr {
  background-color: blue;
}

But every time I add & in a variable it error, follows the example:

table {
  &.bcolor {
    &.bcolor(bc-, ~">tbody>tr");
  }
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.