【问题标题】:GWT: How to access in one stylesheet constants defined in another stylesheet from the same ClientBundleGWT:如何从同一个 ClientBundle 访问另一个样式表中定义的一个样式表常量
【发布时间】:2010-07-08 00:23:39
【问题描述】:

这个问题最好用一个例子来描述。

我的 GWT 应用中有以下 ClientBundle:

interface Resources extends ClientBundle {
    public static final Resources INSTANCE = GWT.create(Resources.class);

    @Source("defines.css")
    Defines defines();

    @Source("appStyle.css")
    @CssResource.NotStrict
    Style style();

    interface Style extends CssResource {
        String appLogo();
        (...)
    }

    interface Defines extends CssResource {
        String formInputBackgroundColor();
        String formInputBorderColor();
        (...)
    }
}

appStyle.css 是应用程序使用的主要样式表,defines.css 是仅包含以下常量的样式表:

@def formInputBackgroundColor #D8ECFD;
@def formInputBorderColor #7FAAFF;
(...)

现在我可以毫无问题地在 UIBinder 模板和应用程序代码中使用 defines.css 样式表中的常量,但我不能在我的 appStyle.css 中使用这些常量。

我已经尝试用interface Style extends Defines 替换interface Style extends CssResource,希望从Defines 样式表继承可以让我访问“子”Style 样式表中的常量,但随后 GWT 编译器报错喜欢:

Rebinding my.project.client.resources.Resources
    Creating assignment for style()
        Replacing CSS class names
            The following obfuscated style classes were missing from the source CSS file:
                formInputBorderColor: Fix by adding .formInputBorderColor{}
                formInputBackgroundColor: Fix by adding .formInputBackgroundColor{}
                (...)

有什么办法可以做到吗?

【问题讨论】:

    标签: css gwt cssresource


    【解决方案1】:

    我找到了一种方法,但它远非优雅,我更喜欢另一种解决方案,比如使用某种继承或注释,如果可能的话。

    我让它工作的方式是@eval defines.cssappStyle.css 样式表中我需要的每个常量,但这会导致大量代码重复,而且维护起来很麻烦。

    @eval formInputBackgroundColor Resources.INSTANCE.defines().formInputBackgroundColor();
    @eval formInputBorderColor Resources.INSTANCE.defines().formInputBorderColor();
    

    如果你有更好的解决方案,请分享。

    【讨论】:

      【解决方案2】:

      更换

      @Source("appStyle.css")
      

      @Source({"defines.css", "appStyle.css"})
      

      应该可以解决问题。通过指定两个 css 文件,您的 style() 将成为两者的联合。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-25
        • 1970-01-01
        • 2023-03-28
        • 2011-03-03
        • 1970-01-01
        • 1970-01-01
        • 2023-02-12
        • 2013-02-17
        相关资源
        最近更新 更多