CSS selectors can include tag selectors, category selectors, ID selectors, intersection selectors, union selectors, descendant selectors, global selectors, pseudo-classes, etc. These style applications have been supported in flex.
1. Tag Selector
The tag selector is set according to the type of components in the MXML file. The example is as follows:
<fx:Style>
@namespace s "library:///flex/spark";
@namespace mx "library:///flex/mx";
s|TextInput{
color: #FF0000;
}
s|Button{
color: #FFFF00;
}
</fx:Style>
<s:TextInput text="text input"/>
<s:Button label="button"/>
The colors of the above two controls will change accordingly.
2. Category Selector
A category selector starts with a dot and is followed by a style name in the component represented by the styleName. The example is as follows:
<fx:Style>
@namespace s "library:///flex/spark";
@namespace mx "library:///flex/mx";
.btn2{
color: #FF0000;
}
</fx:Style>
<s:Button label="button2" styleName="btn2"/>
Selector
The ID selector is a category selector that starts with # and is followed by the ID name set in the component. The example is as follows:
<fx:Style>
@namespace s "library:///flex/spark";
@namespace mx "library:///flex/mx";
#btn1{
color: #FF0000;
}
.btn2{
color: #FF00FF;
}
</fx:Style>
<s:Button label="button1"/>
<s:Button label="button2" styleName="btn2"/>
4. Intersection selector
The intersection selector is composed of two selectors directly connected, and the result is that the intersection of the respective element ranges of the two is selected. The example is as follows:
<fx:Style>
@namespace s "library:///flex/spark";
@namespace mx "library:///flex/mx";
s|Button#btn1{
color: #FF0000;
}
s|Button.btn2{
color: #FF00FF;
}
</fx:Style>
<s:Button label="button1"/>
<s:Button label="button2" styleName="btn2"/>
<s:Button label="button3"/>
5. Unity Selector
The union selector is composed of multiple selectors connected by commas. The union selector selects the range selected by each basic selector at the same time. Any type of selector is OK. The example is as follows:
<fx:Style>
@namespace s "library:///flex/spark";
@namespace mx "library:///flex/mx";
s|Button#btn1,s|Button.btn2{
color: #FF0000;
}
</fx:Style>
<s:Button label="button1"/>
<s:Button label="button2" styleName="btn2"/>
<s:Button label="button3"/>
6. Descendant selector
A descendant selector is also called a derived selector. You can use a descendant selector to define styles for child elements in an element. The example is as follows:
<fx:Style>
@namespace s "library:///flex/spark";
@namespace mx "library:///flex/mx";
s|HGroup s|TextInput{
color: #FF0000;
}
</fx:Style>
<s:HGroup verticalAlign="middle">
<s:Label text="Text Input 1"/>
<s:TextInput text="sample"/>
</s:HGroup>
<s:TextInput text="sample"/>
7. Global selector
Global selector global can apply styles to all components, as shown below:
<fx:Style>
@namespace s "library:///flex/spark";
@namespace mx "library:///flex/mx";
global{
color: #FF0000;
}
</fx:Style>
<s:Label text="label"/>
<s:TextInput text="text input"/>
<s:Button label="button"/>
8. Pseudo-Class
Pseudo-classes are used to set the style of components in different states. The examples are as follows:
<fx:Style>
@namespace s "library:///flex/spark";
@namespace mx "library:///flex/mx";
s|Button:up{
color: #FF0000;
}
s|Button:down{
color: #FF00FF;
}
s|Button:over{
color: #0000FF;
}
</fx:Style>
<s:Button label="button"/>
1. Tag Selector
The tag selector is set according to the type of components in the MXML file. The example is as follows:
Copy the codeThe code is as follows:
<fx:Style>
@namespace s "library:///flex/spark";
@namespace mx "library:///flex/mx";
s|TextInput{
color: #FF0000;
}
s|Button{
color: #FFFF00;
}
</fx:Style>
<s:TextInput text="text input"/>
<s:Button label="button"/>
The colors of the above two controls will change accordingly.
2. Category Selector
A category selector starts with a dot and is followed by a style name in the component represented by the styleName. The example is as follows:
Copy the codeThe code is as follows:
<fx:Style>
@namespace s "library:///flex/spark";
@namespace mx "library:///flex/mx";
.btn2{
color: #FF0000;
}
</fx:Style>
<s:Button label="button2" styleName="btn2"/>
Selector
The ID selector is a category selector that starts with # and is followed by the ID name set in the component. The example is as follows:
Copy the codeThe code is as follows:
<fx:Style>
@namespace s "library:///flex/spark";
@namespace mx "library:///flex/mx";
#btn1{
color: #FF0000;
}
.btn2{
color: #FF00FF;
}
</fx:Style>
<s:Button label="button1"/>
<s:Button label="button2" styleName="btn2"/>
4. Intersection selector
The intersection selector is composed of two selectors directly connected, and the result is that the intersection of the respective element ranges of the two is selected. The example is as follows:
Copy the codeThe code is as follows:
<fx:Style>
@namespace s "library:///flex/spark";
@namespace mx "library:///flex/mx";
s|Button#btn1{
color: #FF0000;
}
s|Button.btn2{
color: #FF00FF;
}
</fx:Style>
<s:Button label="button1"/>
<s:Button label="button2" styleName="btn2"/>
<s:Button label="button3"/>
5. Unity Selector
The union selector is composed of multiple selectors connected by commas. The union selector selects the range selected by each basic selector at the same time. Any type of selector is OK. The example is as follows:
Copy the codeThe code is as follows:
<fx:Style>
@namespace s "library:///flex/spark";
@namespace mx "library:///flex/mx";
s|Button#btn1,s|Button.btn2{
color: #FF0000;
}
</fx:Style>
<s:Button label="button1"/>
<s:Button label="button2" styleName="btn2"/>
<s:Button label="button3"/>
6. Descendant selector
A descendant selector is also called a derived selector. You can use a descendant selector to define styles for child elements in an element. The example is as follows:
Copy the codeThe code is as follows:
<fx:Style>
@namespace s "library:///flex/spark";
@namespace mx "library:///flex/mx";
s|HGroup s|TextInput{
color: #FF0000;
}
</fx:Style>
<s:HGroup verticalAlign="middle">
<s:Label text="Text Input 1"/>
<s:TextInput text="sample"/>
</s:HGroup>
<s:TextInput text="sample"/>
7. Global selector
Global selector global can apply styles to all components, as shown below:
Copy the codeThe code is as follows:
<fx:Style>
@namespace s "library:///flex/spark";
@namespace mx "library:///flex/mx";
global{
color: #FF0000;
}
</fx:Style>
<s:Label text="label"/>
<s:TextInput text="text input"/>
<s:Button label="button"/>
8. Pseudo-Class
Pseudo-classes are used to set the style of components in different states. The examples are as follows:
Copy the codeThe code is as follows:
<fx:Style>
@namespace s "library:///flex/spark";
@namespace mx "library:///flex/mx";
s|Button:up{
color: #FF0000;
}
s|Button:down{
color: #FF00FF;
}
s|Button:over{
color: #0000FF;
}
</fx:Style>
<s:Button label="button"/>