WXSS Introduction
Use WXSS to style an AIUI interface with the CSS properties and selectors that AIUI supports. Put page styles in the <style> block of an .ink file or in the matching .wxss file of a multi-file page.
WXSS Features
Use rpx when a length should scale with the viewport width. Use @import to share a stylesheet across pages.
1. Size Unit rpx
AIUI uses 750rpx for the full viewport width. A 375rpx box spans half of that width. Apply the class to a view and preview the page to check its width.
.half-width-box {
width: 375rpx;
height: 100rpx;
background-color: #40ff5e;
}
2. Style Import @import
For a multi-file page registered as pages/index/index, keep its matching index.json and index.wxml in pages/index/. Create common.wxss next to index.wxss and define the shared class in it.
.text-danger {
color: #ff4d4f;
}
At the top of index.wxss, import the shared stylesheet. The path is relative to the file that imports it. Add class="text-danger" to a text component and check that it appears red in the preview.
@import "./common.wxss";
Writing Recommendations
Use class selectors to make it easy to see which styles apply to a component. Use Flexbox to arrange elements within the space the page or Widget has available. Preview at the sizes and in the display modes you support.