如何在较少的 mixin 中使用映射

问题描述 投票:0回答:1

来自文档:

我写道:

#colors() {
    backgroundDarkPrimary: '#0747A6';
    backgroundMedium: '#dfe1e6';
    backgroundLight: '#ebecf0';
    backgroundLightest: '#F4F5F7';
    backgroundLightPrimary: '#D2E5FE';
    backgroundLightSuccess: '#E4FCEF';
}

但是当我在 mixin 中使用它时,出现错误:

留意帮助

less
1个回答
0
投票

为什么要将颜色包裹在“”中?

/* less */

#colors() {
  background: #0747A6;
}

.mixin( @height: 40px, @background: #colors[background] ) {
  height: @height;
  background: @background;
}

div {
  .mixin;
}

codepen

© www.soinside.com 2019 - 2024. All rights reserved.