chdyiboke / weekly

issue and share weekly
5 stars 1 forks source link

不要滥用‘z-index’ #46

Open chdyiboke opened 3 years ago

chdyiboke commented 3 years ago

使用时注意页面其他元素的层级;

chdyiboke commented 3 years ago

在html 中,越后面的元素。默认的层级都是比前面一个元素高

z-index 调节的是同一个节点下的兄弟节点的层级关系。

chdyiboke commented 3 years ago

不犯二准则:对于非浮层元素,避免设置 z-index 值,z-index 值没有任何道理需要超过 2 对于浮层元素,可以通过 JS 获取 body 下子元素的最大 z-index 值,然后在此基础上加 1 作为浮层元素的 z-index 值 深入css理解z-index