How to use the new CSS syntax in flex 4

Source: Internet
Author: User

CSS now provides many features such as advanced options or namespaces. Let's take a look at how to use them. We will show some methods to select and apply some styles to the components: Using namespace for global selection, using ID selection, inheritance, and status selection.

 

Code

 

In this example, I will use two buttons (one belongs to halo and one from SPARK) and one progressbar CONTAINED IN THE vgroup.

Mxml code
  1. <? XML version ="1.0"Encoding ="UTF-8"?>
  2. <S: Application xmlns: FX =Http://ns.adobe.com/mxml/2009"Xmlns: S ="Library: // ns.adobe.com/flex/spark"Xmlns: MX ="Library: // ns.adobe.com/flex/halo"Minwidth ="1024"Minheight ="768">
  3. <FX: style source ="Global.css"/>
  4. <S: layout>
  5. <S: verticallayout/>
  6. </S: layout>
  7. <Mx: button label ="Click me, I'm a halo button! "Id ="Halobutton"/>
  8. <S: button label ="Click me, I'm a spark cool and funky button! "Id ="Sparkbutton"/>
  9. <S: vgroup id ="Mybox">
  10. <Mx: progressbar/>
  11. </S: vgroup>
  12. </S: Application>
<? XML version = "1.0" encoding = "UTF-8"?> <S: Application xmlns: FX = "http://ns.adobe.com/mxml/2009" xmlns: S = "Library: // ns.adobe.com/flex/spark" xmlns: MX = "Library: // ns.adobe.com/flex/halo "minwidth =" 1024 "minheight =" 768 "> <FX: style source =" global.css "/> <s: layout> <s: verticallayout/> </S: layout> <mx: button label = "Click me, I'm a halo button! "Id =" halobutton "/> <s: button label =" Click me, I'm a spark cool and funky button! "Id =" sparkbutton "/> <s: vgroup id =" mybox "> <mx: progressbar/> </S: vgroup> </S: Application>

 

Declare namespace

 

 

Mxml code
    1. @ Namespace s"Library: // ns.adobe.com/flex/spark";
    2. @ Namespace MX"Library: // ns.adobe.com/flex/halo";
 
@ Namespace s "Library: // ns.adobe.com/flex/spark"; @ namespace MX "Library: // ns.adobe.com/flex/halo ";

In this way, if I want to apply some styles to a part, I also need to determine the namespace before my selection operator (like this, S | button {styles ...}). If you can ensure that most of your projects use the spark component, you can also set the spark namespace as the default.

 

Java code
    1. @ Namespace "Library: // ns.adobe.com/flex/spark";
 
@ Namespace "Library: // ns.adobe.com/flex/spark ";

In the example above, you do not need to append the's |.

 

Global Selection

Mxml code
    1. MX | button
    2. {
    3. Color: # ffffff;
    4. }
    5. S | button
    6. {
    7. Color :#000000;
    8. }
 
MX | button {color: # ffffff;} s | button {color: #000000 ;}

Of course, you can still use the class selector by setting the stylename attribute of the component, just like this

Mxml code
    1. . Mystyleclass {
    2. Color: # ff0000;
    3. }
 
. Mystyleclass {color: # ff0000 ;}

 

 

Select My ID

 

If I only want to set the base-color of some components, I will use the ID selector.

Mxml code
    1. # Halobutton
    2. {
    3. Base-color: # 0000ff;
    4. }
    5. # Sparkbutton
    6. {
    7. Base-color: # ffffff;
    8. }
 
# Halobutton {base-color: # 0000ff ;}# sparkbutton {base-color: # ffffff ;}

 

 

 

 

Inheritance Selection

Set the progressbar font in the vgroup to red.

Java code
    1. S | vgroup # mybox MX | progressbar
    2. {
    3. Color: # ff0000;
    4. }
 
S | vgroup # mybox MX | progressbar {color: # ff0000 ;}

 

 

Select status

I think when the tag of my spark button is pressed by the user (the button state is 'low'), the font turns green.

Mxml code
    1. S | vgroup # mybox MX | progressbar
    2. {
    3. Color: # ff0000;
    4. }
S | vgroup # mybox MX | progressbar {color: # ff0000 ;}

 

 

 

Summary

There are a lot of unreasonable implementations of previous CSS functions, and if you have developed html/CSS before using Flex, it will make you quite frustrated.

Now with the new syntax, it is much easier to customize components.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.