微信小程序组件解读和分析:一、view(视图容器 )
view组件说明:
视图容器
跟HTML代码中的DIV一样,可以包裹其他的组件,也可以被包裹在其他的组件内部。用起来比较自由随意,没有固定的结构。
view组件的用法:

示例项目的wxml代码:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
<view class="btnGroup"> <view class="item orange" >退格</view> <view class="item orange" >清屏</view> <view class="item orange" >+/-</view> <view class="item orange" >+</view> </view> <view class="btnGroup"> <view class="item blue" >9</view> <view class="item blue" >8</view> <view class="item blue" >7</view> <view class="item orange" >-</view> </view> <view class="btnGroup"> <view class="item blue" >6</view> <view class="item blue" >5</view> <view class="item blue" >4</view> <view class="item orange" >×</view> </view> <view class="btnGroup"> <view class="item blue" >3</view> <view class="item blue" >2</view> <view class="item blue" >1</view> <view class="item orange" >÷</view> </view> <view class="btnGroup"> <view class="item blue" >0</view> <view class="item blue" >.</view> <view class="item blue" >历史</view> <view class="item orange" >=</view> </view> |
示例项目的WXSS代码:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
|
.btnGroup{ display:flex; flex-direction:row;}.orange{ color: #fef4e9; border: solid 1px #da7c0c; background: #f78d1d;}.blue{ color: #d9eef7; border: solid 1px #0076a3; background: #0095cd;} |
视图样式flex-direction: row的效果图:
WXML代码如下
|
1
2
3
4
5
|
<view class="flex-wrp"> <view class="flex-item red" ></view> <view class="flex-item green" ></view> <view class="flex-item blue" ></view></view> |
WXSS代码如下:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
|
.flex-wrp{ height: 100px; display:flex; background-color: #FFFFFF;}.flex-item{ width: 100px; height: 100px;}.red{ background: red;}.green{ background: green;}.blue{ background: blue;} |
视图样式flex-direction: column的效果图:
WXML代码如下:
|
1
2
3
4
5
|
<view class="flex-wrp column"> <view class="flex-item" style="background: red"></view> <view class="flex-item" style="background: green"></view> <view class="flex-item" style="background: blue"></view></view> |
WXSS代码如下:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
|
.column{ flex-direction:column;}.flex-item{ width: 100px; height: 100px;}.flex-wrp{ height: 100px; display:flex; background-color: #FFFFFF;}.red{ background: red;}.green{ background: green;}.blue{ background: blue;} |
视图样式justify-content: flex-start的效果图:
WXML代码如下:
|
1
2
3
4
5
|
<view class="flex-wrp flex-start"> <view class="flex-item" style="background: red"></view> <view class="flex-item" style="background: green"></view> <view class="flex-item" style="background: blue"></view></view> |
WXSS代码如下:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
|
.flex-start{ flex-direction:row; justify-content: flex-start;}.flex-wrp{ height: 100px; display:flex; background-color: #FFFFFF;}.flex-item{ width: 100px; height: 100px;}.red{ background: red;}.green{ background: green;}.blue{ background: blue;} |
视图样式justify-content: flex-end的效果图:
WXML代码如下:
|
1
2
3
4
5
|
<view class="flex-wrp flex-end"> <view class="flex-item" style="background: red"></view> <view class="flex-item" style="background: green"></view> <view class="flex-item" style="background: blue"></view></view> |
WXSS代码如下:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
|
.flex-end{ flex-direction:row; justify-content: flex-end;}.flex-wrp{ height: 100px; display:flex; background-color: #FFFFFF;}.flex-item{ width: 100px; height: 100px;}.red{ background: red;}.green{ background: green;}.blue{ background: blue;} |
视图样式justify-content: center的效果图:
WXML代码如下:
|
1
2
3
4
5
|
<view class="flex-wrp justify-content-center"> <view class="flex-item" style="background: red"></view> <view class="flex-item" style="background: green"></view> <view class="flex-item" style="background: blue"></view></view> |
WXSS代码如下:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
|
.justify-content-center{ flex-direction:row; justify-content: center;}.flex-wrp{ height: 100px; display:flex; background-color: #FFFFFF;}.flex-item{ width: 100px; height: 100px;}.red{ background: red;}.green{ background: green;}.blue{ background: blue;} |
视图样式justify-content: space-between的效果图:
WXML代码如下:
|
1
2
3
4
5
|
<view class="flex-wrp space-between"> <view class="flex-item" style="background: red"></view> <view class="flex-item" style="background: green"></view> <view class="flex-item" style="background: blue"></view></view> |
WXSS代码如下:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
|
.space-between{ flex-direction:row; justify-content: space-between;}.flex-wrp{ height: 100px; display:flex; background-color: #FFFFFF;}.flex-item{ width: 100px; height: 100px;}.red{ background: red;}.green{ background: green;}.blue{ background: blue;} |
视图样式justify-content: space-around的效果图:
WXML代码如下:
|
1
2
3
4
5
|
<view class="flex-wrp space-around"> <view class="flex-item" style="background: red"></view> <view class="flex-item" style="background: green"></view> <view class="flex-item" style="background: blue"></view></view> |
WXSS代码如下:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
|
.space-around{ flex-direction:row; justify-content: space-around;}.flex-wrp{ height: 100px; display:flex; background-color: #FFFFFF;}.flex-item{ width: 100px; height: 100px;}.red{ background: red;}.green{ background: green;}.blue{ background: blue;} |
视图样式align-items: flex-end的效果图:
WXML代码如下:
|
1
2
3
4
5
|
<view class="flex-wrp align-items-flex-end"> <view class="flex-item" style="background: red"></view> <view class="flex-item" style="background: green"></view> <view class="flex-item" style="background: blue"></view></view> |
WXSS代码如下:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
.align-items-flex-end{ height: 200px; flex-direction:row; justify-content: center; align-items: flex-end;}.flex-wrp{ height: 100px; display:flex; background-color: #FFFFFF;}.flex-item{ width: 100px; height: 100px;}.red{ background: red;}.green{ background: green;}.blue{ background: blue;} |
视图样式align-items: center的效果图:
WXML代码如下:
|
1
2
3
4
5
|
<view class="flex-wrp align-items-center"> <view class="flex-item" style="background: red"></view> <view class="flex-item" style="background: green"></view> <view class="flex-item" style="background: blue"></view></view> |
WXSS代码如下:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
.align-items-center{ height: 200px; flex-direction:row; justify-content: center; align-items: center;}.flex-wrp{ height: 100px; display:flex; background-color: #FFFFFF;}.flex-item{ width: 100px; height: 100px;}.red{ background: red;}.green{ background: green;}.blue{ background: blue;} |
视图样式align-items: flex-start的效果图:
WXML代码如下:
|
1
2
3
4
5
|
<view class="flex-wrp align-items-flex-start"> <view class="flex-item" style="background: red"></view> <view class="flex-item" style="background: green"></view> <view class="flex-item" style="background: blue"></view></view> |
WXSS代码如下:
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
.align-items-flex-start{ height: 200px; flex-direction:row; justify-content: center; align-items: flex-start;}.flex-wrp{ height: 100px; display:flex; background-color: #FFFFFF;}.flex-item{ width: 100px; height: 100px;}.red{ background: red;}.green{ background: green;}.blue{ background: blue;} |
排列方式(flex-direction),用于wxss
|
属性
|
描述
|
|
row
|
横向排列
|
|
column
|
纵向排列
|
弹性项目内容对齐(justify-content),用于wxss
|
属性
|
描述
|
|
flex-start
|
弹性项目向行头紧挨着填充
|
|
flex-end
|
弹性项目向行尾紧挨着填充
|
|
center
|
弹性项目居中紧挨着填充
|
|
space-between
|
弹性项目平均分布在该行上
|
|
space-around
|
弹性项目平均分布在该行上,两边留有一半的间隔空间
|
项目在容器内侧轴方位的对齐方式(align-items),用于wxss
|
属性
|
描述
|
|
stretch
|
默认值,弹性项目被拉伸以适应容器
|
|
center
|
弹性项目位于容器的中心
|
|
flex-start
|
弹性项目位于容器的开头
|
|
flex-end
|
弹性项目位于容器的结尾
|
|
baseline
|
弹性项目位于容器的基线上
|
微信小程序组件解读和分析:一、view(视图容器 )的更多相关文章
- 微信小程序组件解读和分析:六、progress进度条
progress进度条组件说明: 进度条,就是表示事情当前完成到什么地步了,可以让用户视觉上感知事情的执行.progress进度条是微信小程序的组件,和HTML5的进度条progress类似. pro ...
- 微信小程序组件解读和分析:五、text文本
text文本组件说明: text 文本就是微信小程序中显示出来的文本. text文本组件的示例代码运行效果如下: 下面是WXML代码: [XML] 纯文本查看 复制代码 ? 1 2 3 4 <v ...
- 微信小程序组件解读和分析:四、icon图标
icon图标组件说明: icon是一种图标格式,用于系统图标.软件图标等,这种图标扩展名为.icon..ico.常见的软件或windows桌面上的那些图标一般都是ICON格式的.在应用上面很多地方 ...
- 微信小程序组件解读和分析:三、swiper滑块视图
swiper滑块组件说明: 滑块视图容器,用于展示图片,可以通过用户拖拽和设置自动切换属性控制图片的切换 组件的使用示例的运行效果如下: 下面是WXML代码: [XML] 纯文本查看 复制代码 ? ...
- 微信小程序组件解读和分析:十四、slider滑动选择器
slider滑动选择器组件说明: 滑动选择器. slider滑动选择器示例代码运行效果如下: 下面是WXML代码: [XML] 纯文本查看 复制代码 ? 01 02 03 04 05 06 07 08 ...
- 微信小程序组件解读和分析:十、input输入框
input输入框组件说明: 本文介绍input 输入框的各种参数及特性. input输入框示例代码运行效果如下: 下面是WXML代码: [XML] 纯文本查看 复制代码 ? 01 02 03 04 0 ...
- 微信小程序组件解读和分析:八、checkbox复选项
checkbox复选项组件说明: checkbox是小程序表单组件中的一个组件,作用是在表单中引导用户做出选择. 要使用checkbox组件,还需要在同组中所有的checkbox标签外使用checkb ...
- 微信小程序组件解读和分析:十五、switch 开关选择器
switch 开关选择器组件说明: switch,开关选择器.只能选择或者不选.这种属于表单控件或者查询条件控件. switch 开关选择器示例代码运行效果如下: 下面是WXML代码: [XML] 纯 ...
- 微信小程序组件解读和分析:十三、radio单选项目
radio单选项目组件说明: radio:单选项目. radio-group: 单项选择器,内部由多个<radio/>组成. radio单选项目示例代码运行效果如下: 下面是WXML代码: ...
随机推荐
- YTU 2832: 使用指针访问数组元素--程序填空
2832: 使用指针访问数组元素--程序填空 时间限制: 1 Sec 内存限制: 128 MB 提交: 328 解决: 160 题目描述 输入10个整数值到数组中,使用指针来完成对这10个数组元素 ...
- Git 对比两分支中同一文件
语法 git diff <分支名> <分支名> -- 文件名 git diff branch1 branch2 -- path/file.txt 案例 git diff ori ...
- select下拉带图片-模拟下拉
<style> /*下拉列表*/ ul,dl,ol,li {list-style: none;} .dropdown { float: right; position: relative; ...
- 西交校赛 F. GZP and Poker
F. GZP and Poker GZP often plays games with his friends.Today they went to a board game.There are n ...
- 【POJ 3461】 Oulipo
[题目链接] 点击打开链接 [算法] KMP [代码] #include <algorithm> #include <bitset> #include <cctype&g ...
- C++标准编程:虚函数与内联
我们曾经在讨论C++的时候,经常会问到:“虚函数能被声明为内联吗?”现在,我们几乎听不到这个问题了.现在听到的是:“你不应该使print成为内联的.声明一个虚函数为内联是错误的!” 这种说法的两个主要 ...
- 【hyddd驱动开发学习】DDK与WDK
最近尝试去了解WINDOWS下的驱动开发,现在总结一下最近看到的资料. 1.首先,先从基础的东西说起,开发WINDOWS下的驱动程序,需要一个专门的开发包,如:开发JAVA程序,我们可能需要一个JDK ...
- python学习笔记7-异常处理
1 写弄成了读 1 try: fh = open("testfile", "r") fh.write("This is my test file fo ...
- hdoj3664【DP】
题意: 有一种值E=the number of elements where ai > i.比如1 3 2 4,只有3位置是满足的,E=1.然后他会给你一个数组和一个k,问有多少个序列的E=k. ...
- NOIp2017真题模拟赛 By cellur925
果然我还是最菜的==不接受反驳 (先考了day2喵喵喵) Day2 T1:奶酪 期望得分:100分 实际得分:100分 考察:并查集 思路:这题其实之前做过了==.思路还是比较清晰的,读入时预处理出可 ...