-
Notifications
You must be signed in to change notification settings - Fork 5
Supported CSS Selectors
Since Codename One stylesheets are meant to be used with Codename One component hierarchies instead of XML/HTML documents, selectors work a little differently.
-
All selectors (with some specific exceptions discussed below) are interpreted as UIIDs.
-
Only 4 predefined CSS classes are supported:
-
.pressed- Targets the component when in "Pressed" state. -
.selected- Targets the component when in "Selected" state. -
.unselected- Targets the component when in "Unselected" state. -
.disabled- Targets the component when in "Disabled" state.If no class is specified, then the selector targets "all" states of the given component.
The following are a few possible selectors you can include in your stylesheet.
-
Button- Defines styles for the "Button" UIID. -
Button.pressed- Defines styles for the "Button" UIID’s "pressed" state. -
Button, TextField, Form- Defines styles for the "Button", "TextField", and "Form" UIIDs.
Example 1:
The following example creates a simple button with a border, and text aligned center. By default the button will have a transparent background, but when it is pressed, it will have a gray background:
Button {
text-align: center;
border: 1pt solid gray;
background-color: transparent;
}
Button.pressed {
background-color: gray;
}Example 2: Inheriting properties using cn1-derive
The following example defines a custom Button style named "MyButton" that inherits all of the styles of Button but changes the background color to blue.
MyButton {
cn1-derive: Button;
background-color: blue;
}The #Device selector allows you to define which device resolutions this CSS file should target. Mutli-images generated from this style-sheet will only be include variants for device resolutions in the range (min-resolution, max-resolution) as defined in this section. By default all resolutions are generated.
#Device {
min-resolution: 120dpi;
max-resolution: 480dpi;
resolution: 480dpi;
}