2012-02-14 63 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

相關問題