「小程序JAVA实战」小程序的flex布局(22)
转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-22/
之前已经把小程序的框架说完了,接下来说说小程序的组件,在说组件之前,先说说布局吧。源码:https://github.com/limingios/wxProgram.git 中的No.9

小程序的flex布局
- 小程序建议使用flex布局进行排版
>其实div+css的方式也可以,只是官方建议使用flex布局的方式 - flex 就是一个盒装弹性布局
- flex是一个容器,所有的子元素都是它的成员。
整个是一个大盒子,大盒子里面有很多的小块a,b,c,d,e,f都是他的成员,针对其中的成员可以增加对应的样式,可以看出来a,b,d是比较大的,c是最小的,我们可以通过样式控制它们的大小,我们也可以通过order的方式控制他们的位置顺序,一般正常的咱们的页面都有顺序的,可以通过布局的order属性,把顺序给展示出来。
- 定义布局display:flex
- flex 容器的属性
flex-direction:排列方向
flex-wrap:换行规则
justify-content:对齐方式
flex-direction
容器内的方向,方向可以从上到下,从左到右。
- row[flex-direction 默认布局方式]
从左到右
- row-reverse
从右到左
- column
从上到下
- column-reverse
从下到上
- 演示
flex-direction.wxml
<!--flex-direction.wxml-->
<view class="container-row">
<view class='size a'>a</view>
<view class='size b'>b</view>
<view class='size c'>c</view>
<view class='size d'>d</view>
<view class='size e'>e</view>
</view>
<view style='width:100%;height:20rpx;'>
</view>
<view class="container-row-reverse">
<view class='size a'>a</view>
<view class='size b'>b</view>
<view class='size c'>c</view>
<view class='size d'>d</view>
<view class='size e'>e</view>
</view>
<view style='width:100%;height:20rpx;'>
</view>
<view class="container-column">
<view class='size a'>a</view>
<view class='size b'>b</view>
<view class='size c'>c</view>
<view class='size d'>d</view>
<view class='size e'>e</view>
</view>
<view style='width:100%;height:20rpx;'>
</view>
<view class="container-column-reverse">
<view class='size a'>a</view>
<view class='size b'>b</view>
<view class='size c'>c</view>
<view class='size d'>d</view>
<view class='size e'>e</view>
</view>
flex-direction.wxss
.container-row{
display: flex;
flex-direction: row;
}
.container-row-reverse{
display: flex;
flex-direction: row-reverse;
}
.container-column{
display: flex;
flex-direction: column;
}
.container-column-reverse{
display: flex;
flex-direction: column-reverse;
}
.size{
width: 200rpx;
height: 150rpx;
}
.a {
background: red;
}
.b {
background: yellow;
}
.c {
background: blue;
}
.d {
background: green;
}
.e {
background: gold;
}

flex-wrap
容器换行的属性,分别是不换行,换行,逆向换行
- nowrap[flex-nowwrap 默认不换行]
不换行
- wrap
换行
- wrap-reverse
逆向换行
- 演示
container-wrap.wxml
<!--container-wrap.wxml-->
<view class="container-nowrap">
<view class='size a'>a</view>
<view class='size b'>b</view>
<view class='size c'>c</view>
<view class='size d'>d</view>
<view class='size e'>e</view>
</view>
<view style='width:100%;height:100rpx;'>
欢迎访问我的个人网站:idig8.com
公众号:编程坑太多
</view>
<view class="container-wrap">
<view class='size a'>a</view>
<view class='size b'>b</view>
<view class='size c'>c</view>
<view class='size d'>d</view>
<view class='size e'>e</view>
</view>
<view style='width:100%;height:100rpx;'>
欢迎访问我的个人网站:idig8.com
公众号:编程坑太多
</view>
<view class="container-wrap-reverse">
<view class='size a'>a</view>
<view class='size b'>b</view>
<view class='size c'>c</view>
<view class='size d'>d</view>
<view class='size e'>e</view>
</view>
flex-wrap.wxss
.container-nowrap{
display: flex;
flex-wrap: nowrap;
}
.container-wrap{
display: flex;
flex-wrap: wrap;
}
.container-wrap-reverse{
display: flex;
flex-wrap: wrap-reverse;
}
.size{
width: 200rpx;
height: 150rpx;
}
.a {
background: red;
}
.b {
background: yellow;
}
.c {
background: blue;
}
.d {
background: green;
}
.e {
background: gold;
}

flex-wrap
靠那个方向对齐的一个属性
- flex-start[flex-start 默认左对齐]
左对齐
- flex-end
向右对齐
- center【使用最多的方式】
居中对齐
- space-around
在成员元素周围包裹空格
- space-between
在成员元素之前留空白
- 演示
justify-content.wxml
<!justify-content.wxml-->
<view class="container-flex-start">
<view class='size a'>a</view>
<view class='size b'>b</view>
<view class='size c'>c</view>
<view class='size d'>d</view>
<view class='size e'>e</view>
</view>
<view style='width:100%;height:100rpx;'>
欢迎访问我的个人网站:idig8.com
公众号:编程坑太多
</view>
<view class="container-flex-end">
<view class='size a'>a</view>
<view class='size b'>b</view>
<view class='size c'>c</view>
<view class='size d'>d</view>
<view class='size e'>e</view>
</view>
<view style='width:100%;height:100rpx;'>
欢迎访问我的个人网站:idig8.com
公众号:编程坑太多
</view>
<view class="container-center">
<view class='size a'>a</view>
<view class='size b'>b</view>
<view class='size c'>c</view>
<view class='size d'>d</view>
<view class='size e'>e</view>
</view>
<view style='width:100%;height:100rpx;'>
欢迎访问我的个人网站:idig8.com
公众号:编程坑太多
</view>
<view class="container-space-around">
<view class='size a'>a</view>
<view class='size b'>b</view>
<view class='size c'>c</view>
<view class='size d'>d</view>
<view class='size e'>e</view>
</view>
<view style='width:100%;height:100rpx;'>
欢迎访问我的个人网站:idig8.com
公众号:编程坑太多
</view>
<view class="container-space-between">
<view class='size a'>a</view>
<view class='size b'>b</view>
<view class='size c'>c</view>
<view class='size d'>d</view>
<view class='size e'>e</view>
</view>
justify-content.wxss
.container-flex-start{
display: flex;
justify-content: flex-start;
}
.container-flex-end{
display: flex;
justify-content: flex-end;
}
.container-center{
display: flex;
justify-content: flex-center;
}
.container-space-around{
display: flex;
justify-content: space-around;
}
.container-space-between{
display: flex;
justify-content: space-between;
}
.size{
width: 50rpx;
height: 150rpx;
}
.a {
background: red;
}
.b {
background: yellow;
}
.c {
background: blue;
}
.d {
background: green;
}
.e {
background: gold;
}

flex成员元素的样式设置
顺序和比例分配
- order
通过数字对flex容器内部的成员设置显示的顺序
- flex
设置每个成员所占行级的显示比例
- 演示
order-flex.wxml
<!--order-flex.wxml-->
<view class="container">
<view class='size a'>a</view>
<view class='size b'>b</view>
<view class='size c'>c</view>
<view class='size d'>d</view>
<view class='size e'>e</view>
</view>
<view style='width:100%;height:100rpx;'>
欢迎访问我的个人网站:idig8.com
公众号:编程坑太多
</view>
order-flex.wxss
.container{
display: flex;
justify-content: flex-start;
}
.size{
height: 150rpx;
}
.a {
background: red;
order:5;
flex:4;
}
.b {
background: yellow;
order:1;
flex:1;
}
.c {
background: blue;
order:3;
flex:2;
}
.d {
background: green;
order:32;
flex:3;
}
.e {
background: gold;
order:4;
flex:2;
}

PS:flex布局基本说完了,基本也给各种场景下的属性含义直观的方式进行了演示,但是老铁虽然我搞完了,但是你们如果想学小程序还是勤加练习的,好脑子不如烂笔头对吧!
「小程序JAVA实战」小程序的flex布局(22)的更多相关文章
- 「小程序JAVA实战」小程序的留言和评价功能(70)
转自:https://idig8.com/2018/10/28/xiaochengxujavashizhanxiaochengxudeliuyanhepingjiagongneng69/ 目前小程序这 ...
- 「小程序JAVA实战」小程序的举报功能开发(68)
转自:https://idig8.com/2018/09/25/xiaochengxujavashizhanxiaochengxudeweixinapicaidancaozuo66-2/ 通过点击举报 ...
- 「小程序JAVA实战」小程序的个人信息作品,收藏,关注(66)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudegerenxinxizuopinshoucangguanzhu65 ...
- 「小程序JAVA实战」小程序的关注功能(65)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeguanzhugongneng64/ 在个人页面,根据发布者个人和 ...
- 「小程序JAVA实战」小程序的视频点赞功能开发(62)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudeshipindianzangongnengkaifa61/ 视频点 ...
- 「小程序JAVA实战」小程序的springboot后台拦截器(61)
转自:https://idig8.com/2018/09/24/xiaochengxujavashizhanxiaochengxudespringboothoutailanjieqi60/ 之前咱们把 ...
- 「小程序JAVA实战」小程序首页视频(49)
转自:https://idig8.com/2018/09/21/xiaochengxujavashizhanxiaochengxushouyeshipin48/ 视频显示的内容是视频的截图,用户的头像 ...
- 「小程序JAVA实战」小程序视频封面处理(48)
转自:https://idig8.com/2018/09/16/xiaochengxujavashizhanxiaochengxushipinfengmianchuli47/ 截图这块,在微信小程序工 ...
- 「小程序JAVA实战」小程序上传短视频(46)
转自:https://idig8.com/2018/09/14/xiaochengxujavashizhanxiaochengxushangchuanduanshipin45/ 个人信息:用户上传短视 ...
随机推荐
- Jmeter图形结果
样本数目:总共发送到服务器的请求数 最新样本:代表时间的数字,是服务器响应最后一个请求的时间 吞吐量:服务器每分钟处理的请求数.是指在没有帧丢失的情况下,设备能够接受的最大速率. 平均值:总运行时间除 ...
- maven搭建ssm框架是使用最新mysql 6.0jar遇到的问题
作者:blouc@qq.com本文为作者原创,转载请注明出处:https://www.cnblogs.com/oucbl/p/5940556.html 今天学习SSM框架整合,完成Spring和myb ...
- Codeforces 914H Ember and Storm's Tree Game 【DP】*
Codeforces 914H Ember and Storm's Tree Game 题目链接 ORZ佬 果然出了一套自闭题 这题让你算出第一个人有必胜策略的方案数 然后我们就发现必胜的条件就是树上 ...
- 优化 UWP 中图片的内存占用
跟图片打交道的 UWP 应用或多或少都会遇到图片带来的性能问题,就算不主要处理图片,做个论坛做个新闻客户端都涉及到大量图片.一个帖子.一篇文章里多半都是些高清大图,这些图片一张即可占用程序 1~2M ...
- ASP.NET中几种加密方法
下面就是ASP.NET中几种加密方法.加密算法有两种,也就是上面提到的MD5和SHA1,这里我举的例子是以MD5为例,SHA1大致相同,只是使用的类不一样. MD5的全称是Message-Digest ...
- selenium 上传文件方法补充——SendKeys、win32gui
之前和大家说了input标签的上传文件的方式: <selenium2 python 自动化测试实战>(13)——上传文件 现在好多网站上传的标签并不是input,而是div之类的比如: 全 ...
- js中将时间(如:2017-10-8 22:44:55)转化为时间搓,时间戳转为标准格式时间
function split_time(time){//将当前时间转换成时间搓 例如2013-09-11 12:12:12 var arr=time.split(" "); var ...
- ballerina 学习八 Parallel( 并行处理)
实际上就是并行进行任务的处理 简单例子 代码 import ballerina/io; function main (string… args) { worker first { io:println ...
- InnoSetup 打包Winform程序
在VS2012之前,我们做安装包一般都是使用VS自带的安装包制作工具来创建安装包的,VS2012.VS2013以后,微软把这个去掉,集成使用了InstallShield进行安装包的制作了,虽然思路差不 ...
- Python 函数 -range()
range() pytho range() 函数可创建一个整数列表,一般用在 for 循环中. 语法: range(start, stop[, step]) start: 计数从 start 开始.默 ...