简体   繁体   English

使用CSS定义Flex 4外观

[英]Defining Flex 4 Skins with CSS

I am trying to define my Flex 4 Skins via CSS but I my custom skin will not display. 我试图通过CSS定义我的Flex 4皮肤,但我的自定义皮肤将无法显示。 Here is what I am doing: 这是我在做的事情:

In my application I import my css and define the styleName in my button: 在我的应用程序中,我导入我的CSS并在我的按钮中定义styleName:

        <fx:Style source="styles.css"/>
        <s:Button label="Button" styleName="circle"/>

Here is my CSS: 这是我的CSS:

@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";

s|Button.circle
{
    skinClass: ClassReference("skins.buttons.CircleButton");
}

My understanding is that my button should be supplied it's skinClass via the CSS but it fails to work. 我的理解是我的按钮应该通过CSS提供它的skinClass但它无法工作。 If I define the skinClass directly like below it works fine: 如果我像下面那样直接定义skinClass它可以正常工作:

<s:Button label="Button" skinClass="skins.buttons.CircleButton"/>

Any help would be appreciated. 任何帮助,将不胜感激。

Per the official Flex CSS documentation : 根据官方Flex CSS文档

Class Selector: A CSS class selector matches components that meet a class condition. 类选择器:CSS类选择器匹配满足类条件的组件。 The CSS syntax to declare a class selector is to prefix the condition with a dot. 声明类选择器的CSS语法是在条件前加一个点。 You can either declare a class selector as a condition of a type selector, or universally to any type that meets the class condition. 您可以将类选择器声明为类型选择器的条件,也可以将其声明为满足类条件的任何类型。

.header { background-color: #CCCCCC; }

HBox.footer { background-color: #999999; }

Note: In Flex a class condition is met using the styleName attribute on a component. 注意:在Flex中,使用组件上的styleName属性满足类条件。 For example, you may have two classes of HBox: "header" and "footer". 例如,您可能有两类HBox:“header”和“footer”。 Above, the first selector applies to any component with styleName="header"; 上面,第一个选择器适用于styleName =“header”的任何组件; the second selector should only apply to HBox components with styleName="footer" (something that actually needs to be fixed and enforced in Gumbo, as to-date class selectors have only been universal and any type in the selector is ignored). 第二个选择器应该仅应用于具有styleName =“footer”的HBox组件(实际上需要在Gumbo中修复和强制执行,因为迄今为止的类选择器只是通用的,并且忽略了选择器中的任何类型)。

It looks like selectors may not be working in Gumbo... 看起来选择器可能无法在Gumbo中工作......

Make sure you have your CSS file under the root Application file first. 确保首先在根应用程序文件下包含CSS文件。 Second, I would try to do the css without the type selector, so instead of s|Button.circle , just do .circle . 其次,我会尝试在没有类型选择器的情况下执行css,所以不要使用s|Button.circle ,只需执行.circle

EDIT 编辑

You can also try putting the style in a Style tag within the same container as your button to see if that works. 您还可以尝试将样式标记放在与按钮相同的容器中,以查看是否有效。 Are you sure your application can find your style.css? 你确定你的应用程序可以找到你的style.css吗? Showing more code might help the situation. 显示更多代码可能有助于这种情况。

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

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