2015-02-10 105 views
0

我想分配一些动态变量名称使用较少(第一次使用它)...但我没有试过似乎工作。看完所有文档后,我想出了这个,但它仍然不工作:动态变量名称与更少

// jellybeans 
@opacity: 1; 

@black-jellybeans: rgba(59,59,59,@opacity);  // #3b3b3b 
@red-jellybeans:  rgb(207,106,76,@opacity);  // #cf6a4c 
@green-jellybeans: rgba(153,173,106,@opacity); // #99ad6a 
@yellow-jellybeans: rgba(216,173,76,@opacity);  // #d8ad4c 
@blue-jellybeans:  rgba(89,123,197,@opacity);  // #597bc5 
@magenta-jellybeans: rgba(160,55,176,@opacity);  // #a037b0 
@cyan-jellybeans:  rgba(113,185,248,@opacity); // #71b9f8 
@white-jellybeans: rgba(173,173,173,@opacity); // #adadad 

// the palette to use 
@palette: "jellybeans"; 

@black: "[email protected]{palette}"; 
@red:  "[email protected]{palette}"; 
@green: "[email protected]{palette}"; 
@yellow: "[email protected]{palette}"; 
@blue: "[email protected]{palette}"; 
@magenta: "[email protected]{palette}"; 
@cyan: "[email protected]{palette}"; 
@white: "[email protected]{palette}"; 

有什么建议吗?

+0

它应该工作伴侣。当使用变量(比如'color:@@ black;')时,你是否使用双“@”,因为需要完成这个操作? – Harry 2015-02-10 07:19:00

+1

虽然这将与'@@'当然一起工作,这个问题本身看起来像一个“XY问题”,那么你究竟在试图达到这个目的? (例如,如果你想在同一个文件中的不同主题之间切换,你不需要在所有这些变量上附加“主题”后缀或其他内容,那么就有更干净和更简单的方法)。 – 2015-02-10 08:51:43

+0

@哈里谢谢,我没有。测试它,你是正确的。 – nfarrar 2015-02-10 15:04:40

回答

3

使用:

@cyan: "[email protected]{palette}"; 
p{ 
color: @@cyan; 
} 

@whitename: "[email protected]{palette}"; 
    @white: @@whitename; 

    p{ 
    color: @white; 
    } 
+0

谢谢,它的工作原理! – nfarrar 2015-02-10 15:03:35