Reusing LESS nested styles

陌路散爱 提交于 2020-06-24 23:19:12

问题


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?


回答1:


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




回答2:


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.




回答3:


Since you can't reuse .unstyled when it's a nested style and you probably don't want to edit the Bootstrap source code, I'd suggest you just assign both classnames to your list:

<ul class="unstyled my-list" />


来源:https://stackoverflow.com/questions/12626178/reusing-less-nested-styles

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!