search
HomeWeChat AppletMini Program DevelopmentIntroduction to WXSS in WeChat Mini Program

Introduction to WXSS in WeChat Mini Program

Jun 27, 2018 pm 05:40 PM
wxssWeChat applet

This article mainly introduces the relevant information of WeChat applet WXSS, and attaches simple example code. Friends in need can refer to

WXSS

##WXSS( WeiXin Style Sheets) is a style language designed by MINA for describing WXML component styles.


WXSS is used to determine how WXML components should be displayed.


In order to adapt to the majority of front-end developers, our WXSS has most of the features of CSS. At the same time, in order to be more suitable for developing WeChat applets, we have expanded and modified the CSS.


Compared with css, our extended features are:


Dimension unitStyle import

Size unit

rpx (responsive pixel): can be adapted according to the screen width. The specified screen width is 750rpx. For example, on iPhone 6, the screen width is 375px and there are 750 physical pixels in total, then 750rpx = 375px = 750 physical pixels, 1rpx = 0.5px = 1 physical pixel.

Devicerpx to px (screen width/750)px to rpx (750/screen width)iPhone51rpx = 0.42px#1px = 2.34pxiPhone61rpx = 0.5px1px = 2rpxiPhone6s1rpx = 0.552px1px = 1.81rpx
rem (root em): Specifies the screen width to be 20rem; 1rem = (750/20)rpx.


Suggestion: When developing WeChat mini programs, designers can use iPhone6 ​​as the standard for visual drafts.

Style import

Use the @import statement to import an external style sheet. @import is followed by the relative path of the external style sheet that needs to be imported. Use; to indicate the end of the statement. .

Sample code:

/** common.wxss **/
.small-p{
 padding:5px;
}

##
/** app.wxss **/
@import "common.wxss";
.middle-p:{
 padding:15px;
}

Inline style

MINA components support using style and class attributes to control the style of the component.


style: Static styles are written uniformly into classes. style receives dynamic styles and will parse them at runtime, so do not write static styles into style to avoid affecting the rendering speed.

<view style="color:{{color}};" />

class: used to specify style rules. Its attribute value is a collection of class selector names (style class names) in the style rules. The style class name does not need to be accompanied by., the style class name. Separate with spaces.

<view class="normal_view" />

Selector

Currently supported selectors are:

Selector.classidelementelement, element::after::before
Sample Sample description
.intro Select All components with class="intro"
#firstname Select components with id="firstname"
view Select all view components
view checkbox Select the view components of all documents and all checkbox components
view::after In the view component Insert content after
view::before Insert content before the view component
Global styles and local styles

The styles defined in app.wxss are global styles and apply to every page. The styles defined in the wxss file of the page are local styles, which only apply to the corresponding page and will override the same selector in app.wxss.

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

About the introduction of WeChat applet slider


About WeChat applet implementation of top tab (swiper ) Introduction


About WeChat JS-SDK’s function of selecting mobile phone photo upload


The above is the detailed content of Introduction to WXSS in WeChat Mini Program. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment