Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Flex Developer Center /

Exercise 5.3: Using advanced CSS selectors

by Trilemetry

Trilemetry
  • Trilemetry, Inc.

Content

  • Use CSS descendant selectors
  • Use CSS pseudo selectors
  • Use the CSS id selector

Modified

3 May 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flash Builder 4.5 Premium Flex RIA

Requirements

Prerequisite knowledge

  • Exercise 1.1: Setting up Flash Builder and your project files
  • Exercise 5.1: Using text controls
  • Exercise 5.2: Defining selector styles

User level

Beginning

Required products

  • Flash Builder 4.5 Premium (Download trial)

Sample files

  • ex5_03_starter.zip
  • ex5_03_solution.zip

In this exercise, you will use advanced CSS selectors to style the sample application as shown in Figure 1.

Review your tasks for this exercise.
Figure 1. Review your tasks for this exercise.

In this exercise, you will learn how to:

  • Use CSS descendant selectors
  • Use CSS pseudo selectors
  • Use the CSS id selector

Use CSS descendant selectors

In this section you will use a descendant selector to change the Button controls.

  1. Download the ex5_03_starter.zip file if you haven't already and extract the file ex5_03_starter.fxp to your computer.
  2. Open Flash Builder.
  3. Import the ex5_03_starter.fxp file.
  4. Open the ex5_03_starter.css file.
  5. Below the selector for the MonthlyEvents component, create a descendant selector for Button control instances that are located within the Panel containers.
cx|MonthlyEvents { color: #0B85B7; } s|Panel s|Button { }
  1. Within the selector, assign the color property to #000000 (black) and the chromeColor property value to #64BC48 (green).
s|Panel s|Button { color: #000000; chromeColor: #64BC48; }
  1. Save the file.
  2. Run the application.

    You should see the buttons located within the panels have a green background and black text, whereas the Logout button is unchanged (see Figure 2). The descendant selector only affected Button controls that are in Panel containers.

    The Scroller control is also a descendant of the Panel container and uses Spark Button controls in its skin for the track, thumb, up, and down buttons. As a result, any color property applied to a Spark Button control within a Panel container will also be applied to the Scroller control (see Figure 2).

See the Button controls located within the Panel containers are yellow.
Figure 2. See the Button controls located within the Panel containers are yellow.
  1. Return to the ex5_03_starter.css file in Flash Builder.
  2. Below the descendant selector for Button controls within Panel containers, create a descendant selector for the Button controls used within Scroller controls within Panel containers.
s|Panel s|Button { color: #000000; chromeColor: #64BC48; } s|Panel s|Scroller s|Button { }
  1. Within the selector, assign the chromeColor property value to #555555 (dark gray).
s|Panel s|Scroller s|Button { chromeColor: #555555; }
  1. Save the file and run the application.

The scrollbars within the panels are now dark gray (see Figure 3).

Create a descendant selector to style the Scroller controls.
Figure 3. Create a descendant selector to style the Scroller controls.

Use CSS pseudo selectors

In this section you will use pseudo selectors to change the color of Button controls based on their current state.

  1. Return to the ex5_03_starter.css file in Flash Builder.
  2. Change the Panel container descendant selector so that it applies to the down state of the Button control.
s|Panel s|Button:down { color: #000000; chromeColor: #64BC48; }
  1. Save the file and run the application.
  2. Click each button within the application and take note of the down state.

    You should see that the buttons within the panels have a green down state whereas the Logout button does not (see Figure 4).

The buttons in the panels, when clicked, are yellow.
Figure 4. The buttons in the panels, when clicked, are yellow.
  1. Return to the ex5_03_starter.css file in Flash Builder.
  2. Below the Panel container descendant selector, add a selector for the up state of the Button control and assign the color property value to #FFFFFF (white) and the chromeColor property value to #555555 (dark gray).
s|Panel s|Button:down { color: #000000; chromeColor: #64BC48; } s|Button:up { color: #FFFFFF; chromeColor: #555555; }
  1. Below the selector for the up state, add a descendant selector for the over state for the Button controls within the Panel containers and assign the color property a value of #000000 (black) and the chromeColor property value to #0D86B8 (blue).
s|Button:up { color: #FFFFFF; chromeColor: #555555; } s|Panel s|Button:over { color: #000000; chromeColor: #0D86B8; }
  1. Save the file and run the application.

You should see all the buttons in the application are a dark gray color and turn blue when the mouse is over them (see Figure 5).

Note that the scroll bar is also affected by these changes.

See the Button control over and up state color changes.
Figure 5. See the Button control over and up state color changes.
  1. Return to the ex5_03_starter.css file in Flash Builder.
  2. Locate the descendant selector for the Button control used within the Scroller control within the Panel container.
  3. Change the descendant selector so that it applies to the over state of the Button control.
s|Panel s|Scroller s|Button:over { chromeColor: #555555; }
  1. Under this instance of the descendant selector, create another descendant selector for the Button controls in the Scroller control within the Panel container and apply it to the down state of the Button control.
  2. Add the chromeColor property to the descendant selector and give it a value of #555555.
s|Panel s|Scroller s|Button:over { chromeColor: #555555; } s|Panel s|Scroller s|Button:down { chromeColor: #555555; }
  1. Save the file and run the application.

    You should see that when you mouse over or click on the scroll bar, the color is now gray (see Figure 6).

The Scroller color for the down and over states is gray.
Figure 6. The Scroller color for the down and over states is gray.

Use the CSS id selector

In this section, you will use a CSS id selector to change the color of the employee name within the EmployeeOfTheMonth component.

  1. Return to Flash Builder.
  2. From the Package Explorer view, locate the components folder and open the EmployeeOfTheMonth.mxml file.
  3. Locate the Label control with the text property value assigned to ATHENA PARKER.
  4. To the Label control, add the id property with a value of employeeName.
<s:Label id="employeeName" text="ATHENA PARKER" fontWeight="bold"/>
  1. Save the file.
  2. Open ex5_03_starter.css.
  3. At the bottom of the file, use the id selector (#) and the Label control's id property value, employeeName.
#employeeName { }
  1. Within the id selector, add the color property and assign a value of #FF0000.
#employeeName { color: #FF0000; }
  1. Save the file and run the application.

    The employee name within the Employee of the Month panel is now red (see Figure 7).

The employee name is now red.
Figure 7. The employee name is now red.

In this exercise you used advanced CSS selectors to style the sample application.

Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License+Adobe Commercial Rights

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

More Like This

  • Exercise 2.1: Handling a user event
  • Exercise 3.4: Passing data to the server with the RemoteObject class
  • Exercise 2.2: Using the event object
  • Exercise 3.5: Using formatters
  • Exercise 3.6: Validating form data
  • Exercise 2.3: Using the addEventListener() method
  • Exercise 3.7: Using two-way binding
  • Exercise 1.2: Creating an application user interface
  • Exercise 1.3: Generating an email address using data binding
  • Exercise 1.4: Adding data to your application

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement