Cascading Style Sheets (CSS) is a language used to describe the HML page structure. All HML components have default styles. You can customize styles for these components using CSS to design various pages.
Logical px set by <length>:
Percentage set by <percentage>: The component size is represented by its percentage of the parent component size. For example, if the width <percentage> of a component is set to 50%, the width of the component is half of its parent component's width.
CSS files can be imported using the @import statement. This facilitates module management and code reuse.
The .css file with the same name as the .hml file in each page directory describes the styles of components on the HML page, determining how the components will be displayed.
Internal style: The style and class attributes can be used to specify the component style. Example:
<!-- index.hml --> <div class="container"> <text style="color: red">Hello World</text> </div>
/* index.css */
.container {
justify-content: center;
} External style files: You need to import the files. For example, create a style.css file in the common directory and import the file at the beginning of index.css.
/* style.css */
.title {
font-size: 50px;
} /* index.css */
@import '../../common/style.css';
.container {
justify-content: center;
} A CSS selector is used to select elements for which styles need to be added to. The following table lists the supported selectors.
| Selector | Example | Description |
|---|---|---|
| .class | .container | Selects all components whose class is container. |
| #id | #titleId | Selects all components whose id is titleId. |
Example:
<!-- Pagelayoutexample.hml -->
<div id="containerId" class="container">
<text id="titleId" class="title">Title</text>
<div class="content">
<text id="contentId">Content</text>
</div>
</div> /* Pagestyleexample.css */
/* Set the style for the components whose class is title. */
.title {
font-size: 30px;
}
/* Set the style for the components whose id is contentId. */
#contentId {
font-size: 20px;
} The specificity rule of the selectors complies with the W3C rule, which is only available for inline styles, id, and class. (Inline styles are those declared in the style attribute.)
When multiple selectors point to the same element, their priorities are as follows (in descending order): inline style > id > class.