Similar to CSS style, ASCF style is used to describe the styles and determine the display effects of HXML components.
To better develop atomic services, ASCF inherits from CSS and expands its features, including style import, global style, and local style.
The responsive pixel (rpx) unit is supported in ASCF. It is adaptive based on the screen width and specifies the screen width to 750 rpx.
You can use the @import statement to import an external style sheet. @import is followed by the path of the external style sheet and ends with a semicolon (;).
Sample code:
/* /page/common/index.css */
.import-color {
color: red;
} /* /page/index/index.css */
@import "/page/common/index.css";
.classColor {
color: blue;
} The style and class attributes can be used to specify the component style.
Sample code:
style: receives dynamic styles, which are parsed at runtime.
<view style="color:{{styleColor}};" /> class: specifies a style rule. The attribute value is a set of class selector names (style class names) in the style rule. Style class names do not contain dots (.) and are separated by spaces.
<view class="classColor" />
Currently, the following selectors are supported.
| Selector | Example | Description |
|---|---|---|
| Class | .classColor | Selects the component whose class attribute is set to classColor. |
| ID | #idColor | Selects the component whose id attribute is set to idColor. |
| Tag | view | Selects all view components. |
| ::after pseudo-element | view::after | Inserts content after the view component. |
| ::before pseudo-element | view::before | Inserts content before the view component. |