当前位置: 首页 > backend >正文

Uniapp:view容器(容器布局)

目录

  • 一、基本概述
  • 二、属性说明
  • 三、常用布局
    • 3.1 横向布局
    • 3.2 纵向布局
    • 3.3 更多布局
      • 3.3.1 纵向布局-自动宽度
      • 3.3.2 纵向布局-固定宽度
      • 3.3.3 横向布局-自动宽度
      • 3.3.4 横向布局-居中
      • 3.3.5 横向布局-居右
      • 3.3.6 横向布局-平均分布
      • 3.3.7 横向布局-两端对齐
      • 3.3.8 横向布局-自动填充
      • 3.3.9 横向布局-换行展示
      • 3.3.10 横向布局-垂直分布


一、基本概述

view是一个视图容器,本身不显示任何可视化元素。用途都是为了包裹其他真正显示的组件。它类似于传统html中的div,用于包裹各种元素内容。

二、属性说明

属性名类型默认值说明
hover-classStringnone指定按下去的样式类。当 hover-class=“none” 时,没有点击态效果
hover-stop-propagationBooleanfalse指定是否阻止本节点的祖先节点出现点击态,App、H5、支付宝小程序、百度小程序不支持(支付宝小程序、百度小程序文档中都有此属性,实测未支持)
hover-start-timeNumber50按住后多久出现点击态,单位毫秒
hover-stay-timeNumber400手指松开后点击态保留时间,单位毫秒

实例代码

<view class="box-container" hover-class="box-container-hover" hover-start-time="100" hover-stay-time="1000">视图容器</view>
.box-container {width: 200px;height: 200px;background-color: orange;text-align: center;line-height: 200px;
}
.box-container-hover {background-color: blue;
}

三、常用布局

Flex是Flexible Box的缩写,意为“弹性布局”,用来为盒状模型提供最大的灵活性。当设置display: flex后,继续给view等容器组件设置flex-direction:row或column,就可以在该容器内按行或列排布子组件。uni-app推荐使用flex布局。因为flex布局有利于跨更多平台,尤其是采用原生渲染的平台。

3.1 横向布局

在这里插入图片描述

<view class="uni-flex uni-row"><view class="flex-item uni-bg-red">A</view><view class="flex-item uni-bg-green">B</view><view class="flex-item uni-bg-blue">C</view>
</view>
.uni-flex {display: flex;
}
.uni-row {flex-direction: row;
}
.flex-item {width: 33.3%;height: 100px;text-align: center;line-height: 100px;
}
.uni-bg-red{background:#F76260; color:#FFF;
}
.uni-bg-green{background:#09BB07; color:#FFF;
}
.uni-bg-blue{background:#007AFF; color:#FFF;
}

3.2 纵向布局

在这里插入图片描述

<view class="uni-flex uni-column"><view class="flex-item flex-item-V uni-bg-red">A</view><view class="flex-item flex-item-V uni-bg-green">B</view><view class="flex-item flex-item-V uni-bg-blue">C</view>
</view>
.uni-flex {display: flex;
}
.uni-column {flex-direction: column;
}
.flex-item {width: 33.3%;height: 100px;text-align: center;line-height: 100px;
}
.uni-bg-red{background:#F76260; color:#FFF;
}
.uni-bg-green{background:#09BB07; color:#FFF;
}
.uni-bg-blue{background:#007AFF; color:#FFF;
}

3.3 更多布局

在这里插入图片描述

3.3.1 纵向布局-自动宽度

<view class="text">纵向布局-自动宽度</view>
.text {margin: 7px 5px;padding: 0 10px;background-color: #ebebeb;height: 35px;line-height: 35px;text-align: center;color: #777;font-size: 13px;
}

3.3.2 纵向布局-固定宽度

<view class="text" style="width: 300rpx;">纵向布局-固定宽度</view>
.text {margin: 7px 5px;padding: 0 10px;background-color: #ebebeb;height: 35px;line-height: 35px;text-align: center;color: #777;font-size: 13px;
}

3.3.3 横向布局-自动宽度

<view class="uni-flex uni-row"><view class="text">横向布局-自动宽度</view><view class="text">横向布局-自动宽度</view>
</view>
.uni-flex {display: flex;
}
.uni-row {flex-direction: row;
}
.text {margin: 7px 5px;padding: 0 10px;background-color: #ebebeb;height: 35px;line-height: 35px;text-align: center;color: #777;font-size: 13px;
}

3.3.4 横向布局-居中

<view class="uni-flex uni-row uni-center"><view class="text">横向布局-居中</view><view class="text">横向布局-居中</view>
</view>
.uni-flex {display: flex;
}
.uni-row {flex-direction: row;
}
.uni-center {-webkit-justify-content: center;justify-content: center;
}
.text {margin: 7px 5px;padding: 0 10px;background-color: #ebebeb;height: 35px;line-height: 35px;text-align: center;color: #777;font-size: 13px;
}

3.3.5 横向布局-居右

<view class="uni-flex uni-row uni-right"><view class="text">横向布局-居右</view><view class="text">横向布局-居右</view>
</view>
.uni-flex {display: flex;
}
.uni-row {flex-direction: row;
}
.uni-right {-webkit-justify-content: flex-end;justify-content: flex-end;
}
.text {margin: 7px 5px;padding: 0 10px;background-color: #ebebeb;height: 35px;line-height: 35px;text-align: center;color: #777;font-size: 13px;
}

3.3.6 横向布局-平均分布

<view class="uni-flex uni-row"><view class="text uni-aver" style="-webkit-flex: 1;flex: 1;">横向布局-平均分布</view><view class="text" style="-webkit-flex: 1;flex: 1;">横向布局-平均分布</view>
</view>
.uni-flex {display: flex;
}
.uni-row {flex-direction: row;
}
.uni-aver {-webkit-flex: 1;flex: 1;
}
.text {margin: 7px 5px;padding: 0 10px;background-color: #ebebeb;height: 35px;line-height: 35px;text-align: center;color: #777;font-size: 13px;
}

3.3.7 横向布局-两端对齐

<view class="uni-flex uni-row .uni-between"><view class="text">横向布局-两端对齐</view><view class="text">横向布局-两端对齐</view>
</view>
.uni-flex {display: flex;
}
.uni-row {flex-direction: row;
}
.uni-between {-webkit-justify-content: space-between;justify-content: space-between;
}
.text {margin: 7px 5px;padding: 0 10px;background-color: #ebebeb;height: 35px;line-height: 35px;text-align: center;color: #777;font-size: 13px;
}

3.3.8 横向布局-自动填充

<view class="uni-flex uni-row"><view class="text" style="width: 200rpx;">固定宽度</view><view class="text uni-fill">自动占满余量</view>
</view><view class="uni-flex uni-row"><view class="text" style="width: 200rpx;">固定宽度</view><view class="text uni-fill">自动占满</view><view class="text" style="width: 200rpx;">固定宽度</view>
</view>
.uni-flex {display: flex;
}
.uni-row {flex-direction: row;
}
.uni-fill {-webkit-flex: 1;flex: 1;
}
.text {margin: 7px 5px;padding: 0 10px;background-color: #ebebeb;height: 35px;line-height: 35px;text-align: center;color: #777;font-size: 13px;
}

3.3.9 横向布局-换行展示

<view class="uni-flex uni-row uni-wrap"><view class="text" style="width: 280rpx;">一行显示不全,wrap折行</view><view class="text" style="width: 280rpx;">一行显示不全,wrap折行</view><view class="text" style="width: 280rpx;">一行显示不全,wrap折行</view>
</view>
.uni-flex {display: flex;
}
.uni-row {flex-direction: row;
}
.uni-wrap {-webkit-flex-wrap: wrap;flex-wrap: wrap;
}
.text {margin: 7px 5px;padding: 0 10px;background-color: #ebebeb;height: 35px;line-height: 35px;text-align: center;color: #777;font-size: 13px;
}

3.3.10 横向布局-垂直分布

<view class="uni-flex uni-row"><view class="text uni-flex uni-vertical uni-vertical-top"><text>垂直居顶</text></view><view class="text uni-flex uni-vertical uni-vertical-center"><text>垂直居中</text></view><view class="text uni-flex uni-vertical uni-vertical-end"><text>垂直居底</text></view>
</view>
.uni-flex {display: flex;
}
.uni-row {flex-direction: row;
}
.uni-vertical {-webkit-flex: 1;flex: 1;height: 200rpx;-webkit-justify-content: center;justify-content: center;
}
.uni-vertical-top {-webkit-align-items: flex-start;align-items: flex-start;
}
.uni-vertical-center {-webkit-align-items: center;align-items: center;
}
.uni-vertical-end {-webkit-align-items: flex-end;align-items: flex-end;
}
.text {margin: 7px 5px;padding: 0 10px;background-color: #ebebeb;height: 35px;line-height: 35px;text-align: center;color: #777;font-size: 13px;
}
http://www.xdnf.cn/news/890.html

相关文章:

  • IDEA内存配置失效(已解决)
  • unity3d实现物体闪烁
  • unity之协程
  • [Python] 入门核心笔记
  • 超大文件处理——大文件断点续传源码-下载大文件卡死服务器—星辰大文化术——未来之窗超算中心
  • 徐州服务器租用:虚拟主机的应用场景
  • UML 状态图:陪伴机器人系统示例
  • 【图问答】DeepSeek-VL 论文阅读笔记
  • 可编辑23页PPT | 数据中台建设四步方法论:“采、存、通、用”
  • AI之pdf解析:Tesseract、PaddleOCR、RapidPaddle(可能为 RapidOCR)和 plumberpdf 的对比分析及使用建议
  • WPF的发展历程
  • Go语言中的Context
  • Java中如何创建操作线程
  • Cad c# 射线法判断点在多边形内外
  • JVM内存模型与垃圾回收
  • 蚂蚁全媒体总编刘鑫炜再添新职,出任共工新闻社新媒体研究院院长
  • 《FDTD Solutions仿真全面教程:超构表面与光束操控的前沿探索》
  • vue项目通过GetCapabilities获取wms服务元数据信息并在openlayers进行叠加显示
  • prometheus-operator部署服务监控其他节点mysql服务
  • 重构・协同・共生:传统代理渠道数字化融合全链路解决方案
  • 如何远程访问家中服务器-FRP内网穿透详细
  • 获取电脑信息(登录电脑的进程、C盘文件信息、浏览器信息、IP)
  • Windows网络及服务:制作系统盘
  • idea30天使用无限使用
  • uni-app 状态管理深度解析:Vuex 与全局方案实战指南
  • Android audio_policy_configuration.xml加载流程
  • 云原生--基础篇-2--云计算概述(云计算是云原生的基础,IaaS、PaaS和SaaS服务模型)
  • 在 UE5 编辑器中,由于游戏设置 -> EV100 设置,点击播放前后的光照不同。如何保持点击播放前后的光照一致?
  • 如何在腾讯云Ubuntu服务器上部署Node.js项目
  • SVM(支持向量机)