较少的mixin名称评估为颜色/颜色 [英] less mixin name is evaluated to colour/color

查看:117
本文介绍了较少的mixin名称评估为颜色/颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个更少的文件来定义一堆颜色/颜色.每个类别名称都包含相关颜色的名称,例如.colourOrange{..}.colourBorderOrange{..}navLeftButtOrange{..}.

I have a less file to define a bunch of colours/color. Each class name contains the name of the relevant colour, such as .colourOrange{..} or .colourBorderOrange{..} or navLeftButtOrange{..}.

为简单起见,我有一个mixin,它使用参数名称:colour,并以此命名类:

To make this simple I have a mixin that uses a parameter name: colour, and uses this to name the classes thus:

.completeColour(@colourName, @col) {
.colour@{colourName}{
    …
}
.colourBorder@{colourName}{
   …
}
.leftNavButt@{colourName}{

..... } }

….. } }

问题在于,正在将类的名称评估为相关的颜色.因此,在得到的CSS中,没有得到.leftNavButtOrange{}而是得到了.leftNavButt#ffa500{}

The problem is this the names of the classes are being evaluated to the relevant colour. So instead of getting .leftNavButtOrange{} I get .leftNavButt#ffa500{} in the resulting CSS

有没有一种方法可以使用编译器自变量或其他方法停止此操作.基本上我不希望参数被求值,读取但不求值.我可以使用编译器参数来执行此操作,还是需要更改名称,以使它们与myAppOrange之类的颜色不匹配.

Is there a way to stop this with a compiler argument or something. Basically I don't want the parameter to be evaluated, read but not evaluated. Can I do this with a compiler argument or do I need to change the names so they don't match a color such as myAppOrange or something.

推荐答案

这是Less的遗留功能.目前,可以使用以下解决方法之一来解决从颜色名称到十六进制代码转换的问题.

This is a legacy feature of Less. For the time being, one of the below work-around solutions could be used to overcome this color name to hex code conversion.

.completeColour(~"Orange",1);

.completeColour(e("Orange"),1);

这两个选项都明确告诉编译器所传递的值是字符串而不是颜色,因此Less编译器不会将其转换为相应的十六进制代码.

Both the options explicitly tell the compiler that the value being passed is a String and not a Color and hence Less compiler would not convert it to the corresponding hex code.

来源:

  1. 缺少GitHub-如何避免将颜色名称转换为颜色值?
  2. 缺少GitHub-命名颜色的编译会导致十六进制值在插值中的使用不正确
  1. Less GitHub - how to avoid color name be translated into color value?
  2. Less GitHub - Compilation of named colors results in hex values being used incorrectly in interpolations

更新:从2.0.0版开始,如果显式提及颜色作为名称,并且没有其他基于颜色的操作,则从该颜色名称到十六进制代码的转换将不会发生. 2.0.0版本当前处于beta模式.

Update: Starting from version 2.0.0, this color name to hex code conversion would not happen if the color is mentioned explicitly as a name and has no other color based operations on it. Version 2.0.0 is currently in beta mode.

(官方更新: V2升级指南 | 原始来源:更一致的命名颜色变量).

这篇关于较少的mixin名称评估为颜色/颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆