如何在多个 CssResource css 文件中使用相同的 @def?

发布于 2025-01-05 19:11:15 字数 266 浏览 2 评论 0原文

我想说,在一个集中的位置,

@def mainColor = #f00;

然后在我的所有其他 css 文件中,引用 mainColor 而无需重新定义它。然后,当我在一个地方更改 mainColor 时,我的整个应用程序都会改变颜色。

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

I'd like to say, in a single, centralized location,

@def mainColor = #f00;

and then, in all of my other css files, refer to mainColor without having to redefine it. Then when I change mainColor in once place, my entire app changes color.

The best way I can think of so far is to include two @Source files for every CssResource declaration and always include the global def file. Are there any other ways?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

離人涙 2025-01-12 19:11:15

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

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>    

As far as I know, this is your only option:

style.css

@def mainColor #f00;

*.ui.xml

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

The downside to this is the relative path. Each ui.xml will require a different src path.

Alternatively, if you dont mind using a Constants.java file (instead of css),
you could use @eval

<ui:style>
  @eval mainColor com.myproject.client.Styles.INSTANCE.mainColor(); 
  .widget{ color: mainColor; }
</ui:style>    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文