微信小程序 - view覆盖

挺常见的功能,因首次开发微信小程序,故此做一波记录 ~

最终效果:view覆盖
在这里插入图片描述

主要属性
  //1.position 		
  //2.z-index
  //父布局
  position: relative;
  //子布局
  position: absolute;
  //view层级顺序 → 数值越高就离用户越近
  z-index: 1;
实现步骤
父布局(最外层布局)
  • 效果:单一父布局
    在这里插入图片描述
  • 主要属性
 position: relative;
 z-index: 1;
  • 全部属性
.parent_style {
  background-color: #501370;
  height: 50rpx;
  position: relative;
  width: 100%;
  z-index: 1;
}
子布局

注意

  1. 覆盖view的效果,主要基于俩个子View之间,所以下方我们有俩个子view
  2. 通过 z-index 属性,控制view的显示层级

子view1

  • 效果:父布局 + 1个子布局
    在这里插入图片描述
  • 主要属性
position: absolute;
z-index: 2;
  • 全部属性
.big_son_style {
  color: #fff;
  background-color: #73b939;
  font-size: 28rpx;
  height: 100%;
  position: absolute;
  z-index: 2;
}

子view2

  • 效果: 最终效果:view覆盖
    在这里插入图片描述
  • 主要属性
 position: absolute;
 z-index: 3;
  • 全部属性
.small_son_style {
  color: #fff;
  background-color: #f00;
  font-size: 28rpx;
  height: 100%;
  position: absolute;
  z-index: 3;
}
完整代码

.wxml

 <view class='parent_style'>
    <text class='big_son_style'>你觉得女人都是蛮不讲理的吗?</text>
    <text class='small_son_style'>我觉得是...</text>
  </view>

.wxss

.parent_style {
  background-color: #501370;
  height: 50rpx;
  position: relative;
  width: 100%;
  z-index: 1;
}

.big_son_style {
  color: #fff;
  background-color: #73b939;
  font-size: 28rpx;
  height: 100%;
  position: absolute;
  z-index: 2;
}

.small_son_style {
  color: #fff;
  background-color: #f00;
  font-size: 28rpx;
  height: 100%;
  position: absolute;
  z-index: 3;
}
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

远方那座山

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值