校内实训第二天学习笔记

本文主要介绍了微信小程序的基本配置,包括全局和页面的设置,如app:json、app:wxss等。还详细讲解了Flex布局,涵盖其定义、基本概念、容器和项目的属性,最后通过多个实例展示了Flex布局在不同项目数量下的实操应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、微信小程序基本配置

全局的

app:json顶部导航底部导航

app:wxss

project.config.json

每个页面的设置可以覆盖全局的设置

index.json

可以为空,但是必须有{}

设置底部导航条

设置页面图标(icon)

设置页面内容

大概的样子:

二、Flex 布局(部分来自网络,进行了整合)

1.定义

Flex 是 Flexible Box 的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性。

任何一个容器都可以指定为 Flex 布局。

2.基本概念

(1)采用 Flex 布局的元素,称为 Flex 容器(flex container),简称"容器"。它的所有子元素自动成为容器成员,称为 Flex 项目(flex item),简称"项目"。

(2)容器默认存在两根轴:水平的主轴(main axis)和垂直的交叉轴(cross axis)。主轴的开始位置(与边框的交叉点)叫做main start,结束位置叫做main end;交叉轴的开始位置叫做cross start,结束位置叫做cross end。

(3)项目默认沿主轴排列。单个项目占据的主轴空间叫做main size,占据的交叉轴空间叫做cross size。

3.容器的属性

3.1 flex-direction属性

flex-direction属性决定主轴的方向(即项目的排列方向)。

.box {

  flex-direction: row | row-reverse | column | column-reverse;

}

row(默认值):主轴为水平方向,起点在左端。

row-reverse:主轴为水平方向,起点在右端。

column:主轴为垂直方向,起点在上沿。

column-reverse:主轴为垂直方向,起点在下沿。

3.2 flex-wrap属性

默认情况下,项目都排在一条线(又称"轴线")上。flex-wrap属性定义,如果一条轴线排不下,如何换行。

.box{

  flex-wrap: nowrap | wrap | wrap-reverse;

}

它可能取三个值。

(1)nowrap(默认):不换行。

(2)wrap:换行,第一行在上方。

(3)wrap-reverse:换行,第一行在下方。

3.3 flex-flow

flex-flow属性是flex-direction属性和flex-wrap属性的简写形式,默认值为row nowrap。

.box {

  flex-flow: <flex-direction> || <flex-wrap>;

}

3.4 justify-content属性

justify-content属性定义了项目在主轴上的对齐方式。

.box {

  justify-content: flex-start | flex-end | center | space-between | space-around;

}

flex-start(默认值):左对齐

flex-end:右对齐

center:居中

space-between:两端对齐,项目之间的间隔都相等。

space-around:每个项目两侧的间隔相等。所以,项目之间的间隔比项目与边框的间隔大一倍。

3.5 align-items属性

align-items属性定义项目在交叉轴上如何对齐。

.box {

  align-items: flex-start | flex-end | center | baseline | stretch;

}

它可能取5个值。具体的对齐方式与交叉轴的方向有关,下面假设交叉轴从上到下。

flex-start:交叉轴的起点对齐。

flex-end:交叉轴的终点对齐。

center:交叉轴的中点对齐。

baseline: 项目的第一行文字的基线对齐。

stretch(默认值):如果项目未设置高度或设为auto,将占满整个容器的高度。

3.6 align-content属性

align-content属性定义了多根轴线的对齐方式。如果项目只有一根轴线,该属性不起作用。

.box {

  align-content: flex-start | flex-end | center | space-between | space-around | stretch;

}

该属性可能取6个值。

flex-start:与交叉轴的起点对齐。

flex-end:与交叉轴的终点对齐。

center:与交叉轴的中点对齐。

space-between:与交叉轴两端对齐,轴线之间的间隔平均分布。

space-around:每根轴线两侧的间隔都相等。所以,轴线之间的间隔比轴线与边框的间隔大一倍。

stretch(默认值):轴线占满整个交叉轴。

4.项目的属性

4.1 order属性

order属性定义项目的排列顺序。数值越小,排列越靠前,默认为0。

.item {

  order: <integer>;

}

4.2 flex-grow属性

flex-grow属性定义项目的放大比例,默认为0,即如果存在剩余空间,也不放大。

.item {

  flex-grow: <number>; /* default 0 */

}

如果所有项目的flex-grow属性都为1,则它们将等分剩余空间(如果有的话)。如果一个项目的flex-grow属性为2,其他项目都为1,则前者占据的剩余空间将比其他项多一倍。

4.3 flex-shrink属性

flex-shrink属性定义了项目的缩小比例,默认为1,即如果空间不足,该项目将缩小。

.item {

  flex-shrink: <number>; /* default 1 */

}

如果所有项目的flex-shrink属性都为1,当空间不足时,都将等比例缩小。如果一个项目的flex-shrink属性为0,其他项目都为1,则空间不足时,前者不缩小。

4.4 flex-basis属性

flex-basis属性定义了在分配多余空间之前,项目占据的主轴空间(main size)。浏览器根据这个属性,计算主轴是否有多余空间。它的默认值为auto,即项目的本来大小。

.item {

  flex-basis: <length> | auto; /* default auto */

}

它可以设为跟width或height属性一样的值(比如350px),则项目将占据固定空间。

4.5 flex属性

flex属性是flex-grow, flex-shrink 和 flex-basis的简写,默认值为0 1 auto。后两个属性可选。

.item {

  flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]

}

该属性有两个快捷值:auto (1 1 auto) 和 none (0 0 auto)。

建议优先使用这个属性,而不是单独写三个分离的属性,因为浏览器会推算相关值。

4.6 align-self属性

align-self属性允许单个项目有与其他项目不一样的对齐方式,可覆盖align-items属性。默认值为auto,表示继承父元素的align-items属性,如果没有父元素,则等同于stretch。

.item {

  align-self: auto | flex-start | flex-end | center | baseline | stretch;

}

三、Flex布局实操

single.html

单项目

(1)单项目左对齐

.first-face {

  display: flex;

}

(2)单项目居中

.first-face {

  display: flex;

  justify-content: center;

}

(3)单项目右对齐

.first-face {

  display: flex;

  justify-content: flex-end;

}

设置交叉轴对齐方式

(4)

.first-face {

  display: flex;

  align-items: center;

}

(5)

.first-face {

  display: flex;

  justify-content: center;

  align-items: center;

}

(6)

.first-face {

  display: flex;

  justify-content: center;

  align-items: flex-end;

}

(7)

.first-face {

  display: flex;

  justify-content: flex-end;

  align-items: flex-end;

}

twice.html

双项目

(1)

.second-face {

  display: flex;

  justify-content: space-between;

}

(2)

.second-face {

  display: flex;

  flex-direction: column;

  justify-content: space-between;

}

(3)

.second-face {

  display: flex;

  flex-direction: column;

  justify-content: space-between;

  align-items: center;

}

(4)

.second-face {

  display: flex;

  flex-direction: column;

  justify-content: space-between;

  align-items:flex-end;

}

(5)

.second-face {

  display: flex;

}

.second-face .dot:nth-of-type(2) {

  align-self:center;

}

(6)

.second-face {

  display: flex;

  justify-content: space-between;

}

.second-face .dot:nth-of-type(2) {

  align-self: flex-end;

}

three.html

三项目

(1)

.third-face {

  display: flex;

}

.third-face .dot:nth-of-type(2) {

  align-self: center;

}

.third-face .dot:nth-of-type(3) {

  align-self: flex-end;

}

four.html

四项目

(1)

.fourth-face {

  display: flex;

  flex-wrap: wrap;

  justify-content: flex-end;

  align-content: space-between;

}

.fourth-face .column {

  flex-basis: 100%;

  display: flex;

  justify-content: flex-end;

}

(2)

.fourth-face {

  display: flex;

  flex-wrap: wrap;

  justify-content: flex-end;

  align-content: space-between;

}

.fourth-face .column {

       flex-basis: 100%;

  display: flex;

  justify-content: space-between;

}

six.html

六项目

(1)

.sixth-face {

  display: flex;

  flex-wrap: wrap;

  align-content: space-between;

}

.sixth-face .column {

       flex-basis: 100%;

  display: flex;

  justify-content: space-between;

}

(2)

.sixth-face {

  display: flex;

  flex-direction: column;

  flex-wrap: wrap;

  align-content: space-between;

}

(3)

.sixth-face {

  display: flex;

  flex-wrap: wrap;

}

.sixth-face .column {

  flex-basis: 100%;

  display: flex;

}

.sixth-face .column:nth-of-type(2) {

 justify-content: center;

}

.sixth-face .column:nth-of-type(3) {

 justify-content: space-between;

}

nine.html

九项目

.nineth-face {

  display: flex;

  flex-wrap: wrap;

}

.nineth-face .column {

  flex-basis: 100%;

  display: flex;

}

daytwo.html

allflex.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值