怎么写得少?

时间:2014-05-09 12:04:31

标签: less

这是我的Less代码:

i.icon-gps {
  .sprite(@icon-gps);
  display:inline-block;
}
i.icon-home {
  .sprite(@icon-home);
  display:inline-block;
}
i.icon-map {
  .sprite(@icon-map);
  display:inline-block;
}
//and many more

是否可以将其写入一个表达式?

1 个答案:

答案 0 :(得分:2)

如果用量为<i class="icon-gps" ></i>

i.icon
{
    &-gps {
      .sprite(@icon-gps);
      display:inline-block;
    }
    &-home {
      .sprite(@icon-home);
      display:inline-block;
    }
    &-map {
      .sprite(@icon-map);
      display:inline-block;
    }
}

如果用量为<i class="icon icon-gps"></i> (感谢@ Curt&#39>

i.icon
{
    display:inline-block;
    &-gps {
      .sprite(@icon-gps);
    }
    &-home {
      .sprite(@icon-home);
    }
    &-map {
      .sprite(@icon-map);
    }
}