Flex 4 - MXML 组件中的 CSS 类型选择器
有谁知道 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"/>
我没有找到有关此问题的任何信息(除了 Adobe 文档,该文档基本上只是说“这是不可能的”),但我真的很想知道这背后的原因。
有什么我不明白的吗,或者这些选择器实际上完全没用吗?
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题!我需要覆盖 TextInputs 中的默认文本颜色。您可以编辑主 css 文件:
I had this exact same problem! I needed to override the default text color in TextInputs. You can edit the master css file: