当前位置:网站首页>【微信小程序】z-index失效
【微信小程序】z-index失效
2022-04-23 12:16:00 【少年歌行s】
首先看需求:
<view class="A"></view>
<view class="B">
<view class="C"></view>
</view>
我希望层级关系: C > A > B
简单的给 z-index
是不行的,你会发现 C
的 z-index
始终跟随父元素 B
,为什么呢?来仔细看看 z-index
的规则
z-index
只有在position
为absolute | fixed | relative | sticky
时才生效.- 当父元素设置了
z-index
后,其子元素所设置的z-index
都将在父元素内进行排列,这种情况下的子元素不会与父元素外部其他元素出现渲染层次交叉的情况。
第二条也被称为堆叠上下文,这里不再解释这个名词,感兴趣的可以自己搜索一下。我直接说我的理解:
每个被设置 z-index
属性的元素就是一个平行空间,该元素下的子元素只能在该平行空间进行层级比较,而无法与其他平行空间的元素进行层级比较。
说结论:在该HTML布局下,本题无解。
当然,题主还是找到了两种解法,都需要改变HTML布局:
<!-- 最外层套一个父盒子,这样大家都在同一平行宇宙了 -->
<view class="套盒子">
<view class="A"></view>
<view class="B">
<view class="C"></view>
</view>
</view>
<!-- 将 C 盒子拿出来,使用绝对定位,或调整代码顺序使其放在合适位置 -->
<view class="A"></view>
<view class="C"></view>
<view class="B"></view>
这样 z-index
就能生效啦!
版权声明
本文为[少年歌行s]所创,转载请带上原文链接,感谢
https://blog.csdn.net/MinfCONS/article/details/124311224
边栏推荐
- Introduction to metalama 4 Use fabric to manipulate items or namespaces
- 第四章 为IM 启用填充对象之启用和禁用列(IM-4.3 第三部分)
- C# F23. Stringsimilarity Library: String repeatability, text similarity, anti plagiarism
- 第四章 为IM 启用填充对象之强制填充In-Memory对象:教程(IM 4.7)
- Qt一个进程运行另一个进程
- 面了一圈,整理了这套面试题。。
- C set Logo Icon and shortcut icon
- Sigmoid function of activation function
- The fourth chapter is to enable the filling object of IM and enable ADO for im column storage (IM 4.8)
- MySQL 的主从复制配置
猜你喜欢
Force buckle - 70 climb stairs
Next.js 静态数据生成以及服务端渲染的方式
Idea database navigator plug-in
The maximum number of remote desktop servers has been exceeded
Qt一个进程运行另一个进程
[redis series] redis learning 13. Redis often asks simple interview questions
Relu function of activation function
Metalama简介4.使用Fabric操作项目或命名空间
VMware虚拟机使用esxi 导出硬盘vmdk文件
IDEA 代码格式化插件Save Actions
随机推荐
On using go language to create websocket service
如果你是一个Golang面试官,你会问哪些问题?
Fabric 1.0 source code analysis (33) implementation of peer channel command and subcommand
Metalama简介4.使用Fabric操作项目或命名空间
Database Navigator 使用默认MySQL连接提示:The server time zone value ‘Öйú±ê׼ʱ¼ä’ is unrecognized or repres
IM表达式的目的(IM 5.2)
Lesson 23 temporary objects
用户接口和IM表达式(IM 5.6)
1. Construction of electron development environment
激活函数之阶跃函数
WIN10 启动后花屏
How to solve the computer system card?
软件测试基础DAY2-用例执行
The fourth chapter is about enabling and disabling the im column storage of table space for im enabled filling objects (IM 4.5)
[redis series] redis learning 13. Redis often asks simple interview questions
《通用数据保护条例》(GDPR)系列解读三:欧洲子公司如何向国内母公司回传数据?
为什么hash%length==hash&(length-1)的前提是 length 是 2 的 n 次方
初探 Lambda Powertools TypeScript
Introduction to metalama 4 Use fabric to manipulate items or namespaces
How to expand the capacity of the server in the 100 million level traffic architecture? Well written!