WeChat mini-program rpx unit

Source: Internet
Author: User
The unit of rpx is the unit of css size in the applet. rpx can be adaptive according to the screen width. Specify that the screen width is 750rpx. For example, if the screen width of iPhone 6 is 375px and there are 750 physical pixels in total, 750rpx375px750 physical pixel, 1rpx0.

The unit of rpx is the unit of css size in the applet. rpx can be adaptive according to the screen width. Specify that the screen width is 750rpx. For example, if the screen width of iPhone 6 is 375px and there are 750 physical pixels in total, 750rpx = 375px = 750 physical pixel, 1rpx = 0.

Small program size unit

The unit of rpx is the unit of css size in the applet. rpx can be adaptive according to the screen width. Specify that the screen width is 750rpx. For example, if the screen width of iPhone 6 is 375px and there are 750 physical pixels in total, 750rpx = 375px = 750 physical pixel, and 1rpx = 0.5px = 1 physical pixel.

Device Rpx conversion px (screen width/750) Px is converted to rpx (750/screen width)
IPhone 5 1rpx = 0.42px 1px = 2.34rpx
IPhone 6 1rpx = 0.5px 1px = 2rpx
IPhone6s 1rpx = 0.552px 1px = 1.81rpx

The applet also supports the conversion relationship between rem and rpx: rem: specifies that the screen width is 20rem; 1rem = (750/20) rpx
Note: When developing small programs, designers can use iPhone6 as the standard for visual drafts.
Suggestion: in the design draft, if the device width is px, it is easier to calculate px, 1rpx = 1px. in this way, the size of the size measured on the design drawing is as much as rpx, as for how many rem files need to be converted to on different devices, it is handed over to the applet for self-conversion.

Small program style import

You can use the @ import statement to import an external style table. @ import is followed by the relative path of the external style table to be imported.

Sample code:

/** common.wxss **/.small-p {  padding:5px;}
/** app.wxss **/@import "common.wxss";.middle-p {  padding:15px;}
Mini-program inline style

You can use style and class attributes to control the style of a widget.

  • Style: static styles are uniformly written to the class. The style receives dynamic styles and is parsed during runtime. try to avoid writing static styles into the style to avoid affecting the rendering speed.

 
  • Class: specifies a style rule. Its attribute value is a set of class selector names (style class names) in the style rule. style class names do not need to be included. style class names are separated by spaces.

 
Css selector

Currently, applets support the following selectors:

Selector Example Example Description
. Class . Intro Select all components with class = "intro"
# Id # Firstname Select a component with id = "firstname"
Element View Select all view components
Element, element View checkbox Select view components and all checkbox components for all documents
: After View: after Insert content behind the view component
: Before View: before Insert content in front of the view component
Global and local styles of applets

The style defined in app. wxss is a global style that acts on every page. The style defined in the wxss file of the page is a local style. it only applies to the corresponding page and will overwrite the same selector in app. wxss.

For more articles about rpx units of small programs, please follow PHP Chinese network!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.