2012-02-14 51 views
2

我想说,在一个单一的,集中的位置,如何在多个CssResource css文件中使用相同的@def?

@def mainColor = #f00; 

,然后,在我所有的其他的CSS文件,请参阅mainColor不必重新定义它。然后,当我一次更改mainColor时,我的整个应用程序会改变颜色。

到目前为止,我能想到的最佳方式是为每个CssResource声明包含两个@Source文件,并始终包含全局def文件。还有其他方法吗?

+0

能否请您添加自己的@Source例子作为比较的另一个“答案”? – checketts 2012-02-15 06:02:14

+1

我刚把它作为Danny Kirchmeier的回答下面的评论加入。它本质上是相同的技术,具有不同的语法和上下文。 – 2012-02-15 13:31:58

回答

5

据我所知,这是你唯一的选择:

的style.css

@def mainColor #f00; 

* .ui.xml

<ui:style src="../../../styles/style.css"> 
    .widget{ color: mainColor; } 
</ui:style> 

这样做的缺点是相对路径。每个ui.xml将需要一个不同的src路径。

另外,如果你使用Constants.java文件(而不是CSS), 不介意,你可以使用@eval

<ui:style> 
    @eval mainColor com.myproject.client.Styles.INSTANCE.mainColor(); 
    .widget{ color: mainColor; } 
</ui:style>  
+0

OOF。感谢您的建议。这些都很粗糙,但是;) – 2012-02-14 22:58:51

+2

@Thomas Broyer在https://groups.google.com/forum/#!msg/google-web-toolkit/c8XdDDNDNA/dWtkdAENYXMJ上添加了他也使用这种方法。在uibinders之外,他提到了多种@Source技术:'@Source({“path/to/definitions.css”,“foo.css”})FooStyles foo;' – 2012-02-15 13:31:12

相关问题