Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reusing LESS nested styles

Tags:

less

Let's say that I have a style defined using Less:

ul.unstyled,
ol.unstyled {
  margin-left: 0;
  list-style: none;
}

Later on, I want to re-use the unstyled class:

.my-list {
  .unstyled;
}

This doesn't work, however, and I can't figure out the magic to make it work. Any thoughts?

like image 658
Brian Genisio Avatar asked Sep 27 '12 16:09

Brian Genisio


2 Answers

You can't re-use arbitrary class definitions, only mixins (those starting with a dot). In this case you'll need to duplicate it.

like image 189
Christoph Leiter Avatar answered Nov 05 '22 19:11

Christoph Leiter


Try this:

.unstyled {
  margin-left: 0;
  list-style: none;
}

.my-list {
  .unstyled;
}

You won't be able to nest .unstyled if it's defined as ul.unstled and ol.unstyled.

like image 33
Alex Bain Avatar answered Nov 05 '22 19:11

Alex Bain