Flex 4 - MXML 组件中的 CSS 类型选择器

发布于 2024-09-04 10:06:05 字数 969 浏览 8 评论 0原文

有谁知道 CSS 类型选择器不能在 MXML 组件中使用的原因,和/或让它工作的技巧?

我认为绝对没有理由不支持如此简单的功能,我真的很想理解。

毕竟我读到 Flex 4 中的 CSS 比 Flex 3 中的 CSS 好得多,当我被迫重复自己,向所有按钮添加相同的参数时,我发现自己非常失望......

    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        .sampleStyle {   color: red;   }        
    </fx:Style>

    <s:Button label="1" styleName="sampleStyle"/>
    <s:Button label="2" styleName="sampleStyle"/>
    <s:Button label="3" styleName="sampleStyle"/>


...虽然我可以简单地使用类型选择器并使我的 MXML 代码更加清晰和可读。

    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        s|Button {   color: red;   }        
    </fx:Style>

    <s:Button label="1"/>
    <s:Button label="2"/>
    <s:Button label="3"/>


我没有找到有关此问题的任何信息(除了 Adob​​e 文档,该文档基本上只是说“这是不可能的”),但我真的很想知道这背后的原因。
有什么我不明白的吗,或者这些选择器实际上完全没用吗?

Does anybody know the reason why CSS type selectors cannot be used inside MXML components, and/or a trick to make it work?

I see absolutely no reason for a such simple functionnality not to be supported, and I'd really like to understand.

After all I read about CSS in Flex 4 being so much better than in Flex 3, I find myself quite disapointed when I'm forced to repeat myself, addding the same parameter to all my buttons...

    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        .sampleStyle {   color: red;   }        
    </fx:Style>

    <s:Button label="1" styleName="sampleStyle"/>
    <s:Button label="2" styleName="sampleStyle"/>
    <s:Button label="3" styleName="sampleStyle"/>

...while I could simply use a type selector and keep my MXML code a lot cleaner and readable.

    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        s|Button {   color: red;   }        
    </fx:Style>

    <s:Button label="1"/>
    <s:Button label="2"/>
    <s:Button label="3"/>

I didn't found any information on this issue (apart from Adobe documentation which basically just says "that's not possible"), but I'd really like to know the reason behind this.
Is there something I don't get, or are these selectors actually totally useless?

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

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

发布评论

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

评论(1

心头的小情儿 2024-09-11 10:06:05

我遇到了同样的问题!我需要覆盖 TextInputs 中的默认文本颜色。您可以编辑主 css 文件:

my|Component s|Button {
    color: red;
}

I had this exact same problem! I needed to override the default text color in TextInputs. You can edit the master css file:

my|Component s|Button {
    color: red;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文