The WeChat applet page layout adopts Flex
layout. Flex
layout is a new solution proposed by W3c in 2009, which can realize various page layouts simply, completely and responsively.
Flex layout provides the alignment, direction and order of elements in the container, and they can even be dynamic or of indeterminate size.
The main feature of Flex layout is the ability to adjust its child elements to fill the appropriate space in the most suitable method in different screen sizes.
flex layout
Features of Flex layout:
Telescopic in any direction , left, right, down, up
The order can be exchanged and rearranged in the style layer
The main axis and side axis are convenient to configure
Space stretching and filling of child elements
Alignment along the container
WeChat small The program implements Flex
layout. Let’s briefly introduce the use of Flex
layout in WeChat mini programs.
Flexible container
An element with <a href="http://www.php.cn/wiki/927.html" target="_blank">display</a>:flex
or display:block
is a flex container
(flexible container), the sub-elements inside are called flex item
(flexible items), the sub-elements in flex container
are all laid out using Flex
.
display:block
Specify the block container mode, always use a new line to start display, the view container of the WeChat applet (view, scroll-view and swiper ) aredispaly:block
by default.-
display:flex
: Specify the in-line container mode to display child elements in a row. You can use theflex-wrap
attribute to specify it. Whether to wrap the line,flex-wrap
has three values: nowrap (no line wrap) , wrap (line wrap) , wrap-reverse (wrap the first line) Below)
Code usingdisplay:block
(default value):<view class="flex-row" style="display: block;"> <view class="flex-view-item">1</view> <view class="flex-view-item">2</view> <view class="flex-view-item">3</view> </view>
Display effect:
## The display effect of changing
display:flex:
block and
flex from the rendering. The child element
view is displayed in a new line (
block ) or inline display (
flex).
FlexThe flex container of the layout can be laid out in any direction.
The container has two axes by default:
main axis(main axis) and cross axis(cross axis). The starting position of the spindle is
spindle starting point(main start), the end position of the spindle is
spindle end point(main end), and the length of the spindle is
spindle length(main size).
Similarly, the starting point of the cross axis is
the starting point of the cross axis (cross start), the end position is
the end point of the cross axis (cross end), and the length is
the length of the cross axis(cross size). See the picture below for details:
spindle is not necessarily
From left to right, similarly
side axis is not necessarily
from top to bottom, the direction of the main axis is controlled by the
flex-direction attribute , it has 4 optional values:
row
: The horizontal direction from left to right 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 the main axis
column-reverse
The vertical direction from bottom to top is the main axis
Renderings of four main axis direction settings:
flex-direction value is the difference in the arrangement direction.
Example code:
<view > <view class="flex-row" style="display: flex;flex-direction: row;"> <view class="flex-view-item">1</view> <view class="flex-view-item">2</view> <view class="flex-view-item">3</view> </view> <view class="flex-column" style="display:flex;flex-direction: column;" > <view class="flex-view-item">c1</view> <view class="flex-view-item">c2</view> <view class="flex-view-item">c3</view> </view> </view>Running effect:
##flex-direction
Alignment
There are two alignment methods for child elements:
justify-conentjustify-contentDefine the alignment of child elements on the main axis
align-items
Define child The way elements are aligned on the cross axis
There are 5 optional alignment methods:<ul class=" list-paddingleft-2">
<li><p><code>flex-start
Spindle start point alignment (default value)
flex-end
Spindle end point alignment
center
Align center in main axis
space-between
Align ends except The child elements at both ends are outside the container at both ends, and the intervals between other child elements are equal
space-around
The distance between each child element Equal, the distance between the child elements at both ends of the container is the same as the distance between other child elements. The alignment of justify-content
is related to the direction of the main axis. In the figure below, flex-direction
is row
, and the main axis method is from the left. Go to the right
and describe the display effect of jstify-content
5 values:
align-items represents the alignment on the cross axis:
stretch
fills the entire container (default Value)
flex-start
Starting point alignment of side axis
flex-end
side Align the end point of the axis
center
Center the alignment in the side axis
baseline
The alignment of the first line of text of the element
align-tiems is related to the direction of the cross-axis. The following figure uses
flex-direction is
row, the side axis direction is
from top to bottom , and the 5 values describing
align-items display effect:
WeChat public account platform source code download
2.Xiaozhu CMS Life Pass O2O System v2. 0 Exclusive Edition Download
3.小 Pigcms (pigcms) WeChat Marketing System V8.52 Pinhaohao Mall Secondary Development Special Edition
The above is the detailed content of Detailed explanation of Flex layout for WeChat development. For more information, please follow other related articles on the PHP Chinese website!

WordPress网页错位现象解决攻略在WordPress网站开发中,有时候我们会遇到网页元素错位的情况,这可能是由于不同设备上的屏幕尺寸、浏览器兼容性或者CSS样式设置不当所致。要解决这种错位现象,我们需要仔细分析问题、查找可能的原因,并逐步进行调试和修复。本文将分享一些常见的WordPress网页错位问题以及相应的解决攻略,同时提供具体的代码示例,帮助开

flex布局的常用属性有哪些,需要具体代码示例Flex布局是一种用于设计响应式网页布局的强大工具。它通过使用一组灵活的属性,可以轻松控制网页中元素的排列方式和尺寸。在本文中,我将介绍Flex布局的常用属性,并提供具体的代码示例。display:设置元素的显示方式为Flex。.container{display:flex;}flex-directi

Vue是一款非常优秀的前端开发框架,它采用MVVM模式,通过数据的双向绑定实现了非常好的响应式布局。在我们的前端开发中,响应式布局是非常重要的一部分,因为它能够让我们的页面针对不同的设备,显示出最佳的效果,从而提高用户体验。在本文中,我们将会介绍如何使用Vue实现响应式布局,并提供具体的代码实例。一、使用Bootstrap实现响应式布局Bootstrap是一

如何通过CSSFlex弹性布局实现两栏布局CSSFlex弹性布局是一种现代的布局技术,它能够简化网页布局的过程,使得设计与开发者们能够轻松创建出灵活且适应各种屏幕尺寸的布局。其中,实现两栏布局是Flex布局中的常见需求之一。在这篇文章中,我们将会介绍如何使用CSSFlex弹性布局来实现一个简单的两栏布局,并提供具体的代码示例。使用Flex容器和项目在使

Vue是一种流行的JavaScript框架,广泛应用于前端开发中。它的灵活性和强大的功能使得开发人员可以轻松构建交互丰富的Web应用程序。在Vue开发中,flex布局几乎是无处不在的。然而,使用flex布局时,有时会遇到一些样式问题。本文将介绍一些解决flex布局引起的样式问题的方法。首先,让我们了解一下flex布局的基本概念。Flex布局提供了弹性盒子模型

PHP是一种开源的脚本语言,广泛应用于Web开发和服务器端编程,尤其在微信开发中得到了广泛的应用。如今,越来越多的企业和开发者开始使用PHP进行微信开发,因为它成为了一款真正的易学易用的开发语言。在微信开发中,消息的加密和解密是一个非常重要的问题,因为它们涉及到数据的安全性。对于没有加密和解密方式的消息,黑客可以轻松获取到其中的数据,对用户造成威胁

如何通过CSSFlex弹性布局实现不规则的网格布局在网页设计中,常常需要使用网格布局来实现页面的分割和排版,通常的网格布局都是规则的,每个网格大小相同,而有时候我们可能需要实现一些不规则的网格布局。CSSFlex弹性布局是一种强大的布局方式,它可以很容易地实现各种网格布局,包括不规则的网格布局。下面我们将介绍如何利用CSSFlex弹性布局来实现不

如何通过CSSFlex弹性布局实现页面元素的垂直居中在网页设计中,经常会遇到需要将页面元素进行垂直居中的情况。CSSFlex弹性布局是一种优雅简洁且灵活的布局方式,能够轻松实现页面元素的垂直居中。本文将详细介绍如何使用CSSFlex布局实现页面元素的垂直居中,并提供具体的代码示例。一、基本原理使用CSSFlex布局实现页面元素的垂直居中,需要有以下几


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools