WeChat Mini Program View supports two layout methods: Block and Flex
All Views are block by default
If you want to use flex layout, you need to display Style statement:
display:flex;
Let’s introduce the Flex layout of the WeChat applet
Let’s make a simple demo first
<view class="main"> <view class="item item1">1</view> <view class="item item2">2</view> <view class="item item3">3</view> </view>
Add the background color to see it more clearly Some
.main { width: 100%; background-color: antiquewhite; } .item { height: 100rpx; width: 100rpx; } .item1 { background-color: red; } .item2 { background-color: dodgerblue; } .item3 { background-color: greenyellow; }
then probably look like this:
Then we first add display: flex
so that we can use flex layout, Idea, it seems that view will not automatically inherit , you need to add it in every view you want to use.
The first is horizontal layout and vertical layout. To set the attribute flex-direction, it has 4 optional values:
row: horizontal from left to right The direction is the main axis
row-reverse: the horizontal direction from right to left is the main axis
column: the vertical direction from top to bottom is Main axis
column-reverse: The vertical direction from bottom to top is the main axis
flex-start: align the starting point of the main axis (default value )
- ##flex-
- center: Align in the center of the main axis
- space-between: Align both ends, except for the child elements at both ends. Outside the container at both ends, the spacing between other child elements is equal
- space-around: The distance between each child element is equal, The distance between the child elements at both ends of the container is also the same as the distance between
other child elements
- stretch to fill the entire container (default value)
- flex-start aligns the starting point of the side axis (here we manually set the height of the subview to see it more clearly)
- flex-end Align the end of the cross axis
- center Align the center in the cross axis
- baseline aligns with the first line of text of the child element
- nowrap: no line wrapping (default)
- wrap: Line wrap
- wrap-reverse: Line wrap, the first line is at the bottom There is also a sub-View
Let’s take a look at the difference between setting row and row-reverse:
row:
row-reverse:
Then we have to set For the layout direction of elements in the horizontal direction, you need to set the justify-content attribute. It has 5 optional values:
ord## The #er attribute can control the order of sub-elements, and the default is 0. For example, in the above example, if we set item3 to order:-1; we can put item3 in front
flex Commonly used layouts are just these
Those who write WeChat mini programs can try it
Finally, if there is a mini program when It would be even better if it can directly support bootstrap
[Related recommendations]
1. HTML5 mobile application development-detailed introduction to the role of viewport (picture Text)
2. A brief discussion of html5 responsive layout
4. An example tutorial on using co to handle asynchronous processes in small program development
The above is the detailed content of WeChat applet View: flex layout example. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
