简体   繁体   English

我怎样才能使我的css文件可用于Gwt中的整个应用程序?

[英]how can i make my css file available for my entire application in Gwt?

I'm using GWTP and Maven, i have a .css file which specifies different styles for the widgets in my application, and my application has some sub modules also so my question is how can i make my css available for the whole application ? 我正在使用GWTP和Maven,我有一个.css文件,该文件为我的应用程序中的小部件指定了不同的样式,并且我的应用程序还包含一些子模块,所以我的问题是如何使我的CSS可用于整个应用程序? how can i make my css file available for sub modules also? 我如何使我的css文件也可用于子模块?

To benefit from GWT's CssResource advantages (like you do when you say <ui:style src="abc.css"/> ) you'll have to use a ClientBundle. 要利用GWT的CssResource优势(就像您说<ui:style src="abc.css"/> ),您必须使用ClientBundle。

ClientBundles are basically Java classes that represent CSS and other resources. ClientBundle基本上是代表CSS和其他资源的Java类。 Without GWT, you'd put your CSS and images directly into your HTML code. 如果没有GWT,则可以将CSS和图像直接放入HTML代码中。 With GWT, you want to do everything through Java... and that means using Java design patterns. 使用GWT,您想通过Java来做所有事情……这意味着要使用Java设计模式。

As you know, you can't just use a global variable in Java programs, and the same is true for css with GWT. 如您所知,您不仅可以在Java程序中使用全局变量,对于具有GWT的CSS也是如此。 You'll have to pass your CSS classes to your libraries as Java objects. 您必须将CSS类作为Java对象传递给您的库。 You can use static references in many places, but I prefer to actually pass in CSS objects to maximize flexibility later, and I think that's an established best practice. 您可以在许多地方使用静态引用,但是我更喜欢稍后传入CSS对象以最大程度地提高灵活性,并且我认为这是一种既定的最佳实践。

TL;DR: TL; DR:

Figure out ClientBundles and do as you'd normally do to pass Java variables between libraries. 找出ClientBundles,然后像平常一样在库之间传递Java变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM