css的z-index、position、overflow属性混合时Safari的兼容问题,fixed定位+z-index同时使用不生效问题

news/2024/7/19 14:52:05 标签: css, 定位, html, css3, js

~~~转前端啦~~~

问题:position: fixed和z-index同时使用在Safari浏览器中不生效???

浏览器版本

场景1: fixedhtml" title=定位>定位+z-index属性+tranform3D变化同时使用

先看代码:

// html" title=css>css部分
<style>
   .header {
     width: 100%;
     height: 50px;
     background-color: #ccc;
     position: fixed; // 1、重点在这里
     top: 0;
     left: 0;
     z-index: 90;  // 2、在这里
   }
   .sider {
     width: 200px;
     height: 600px;
     background-color: #3136d8;
     position: fixed;  // 3、这里
     top: 30px;
     left: 30px;
     z-index: 100;  // 4、还有这里
     transform: perspective(1000px) rotateY(45deg); 
     // 5、还有最后这一句---重中之重
   }
</style>
// html
 <div class="header"></div>
 <div class="sider"></div>

正常来讲,sider的一部分会盖住header。
打开谷歌瞅一眼,很好,和预想的结果是一样子的
谷歌打开的效果,和预期一样子的

接下来,用Safari打开试一下,瞅一下效果看下面
Safari打开的效果
居然不一样!!!

场景1的解决方案

1、 在变换的元素身上套上一层父元素

上代码~

// html结构
<div class="header"></div>
<div class="containter">  // 在这里--多套了一层结构
    <div class="sider">
</div>
// html" title=css>css
.header {
   width: 100%;
   height: 50px;
   background-color: #ccc;
   position: fixed;
   top: 0;
   left: 0;
   z-index: 90;
}
.containter {       // 变化的点在这里----
    width: 200px;
    height: 600px;
    position: fixed;
    top: 30px;
    left: 30px;
    z-index: 100;
   /* overflow: hidden; */
}
.sider {  // 还有这里,也稍微改了哦
    background-color: #3136d8;
    width: 100%;
    height: 100%;
    transform: perspective(1000px) rotateY(45deg);
}

瞅一眼效果~OK,正常了
safari正常

2、给需要在后面的元素设置负的translateZ

看代码~

// html" title=css>css
.header {
   width: 100%;
    height: 50px;
    background-color: #ccc;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 90;
    transform: translateZ(-100px);  // 重点在这里 
}
.sider {
    width: 200px;
    height: 600px;
    position: fixed;
    top: 30px;
    left: 30px;
    z-index: 100;
    /* overflow: hidden; */
    background-color: #3136d8;
    transform: perspective(1000px) rotateY(45deg);
}
// html结构不变
    <div class="header"></div>
    <div class="sider"></div>

瞅一眼效果~!也很棒
在这里插入图片描述

场景2 Safari下子元素fixedhtml" title=定位>定位会被父级overflow:hidden给隐藏掉

看下问题先~

// html结构
 <div class="header"></div>
 <div class="sider">
     <div class="sider-child"></div>
 </div>
 // html" title=css>css
 .header {
   width: 100%;
   height: 50px;
   background-color: #ccc;
   position: fixed;
   top: 0;
   left: 0;
   z-index: 90;  // 这里
}
.sider {
   width: 200px;
   height: 600px;
   position: fixed;  
   top: 30px;
   left: 30px;
   z-index: 100;  
   overflow: hidden; // 这里
   background-color: #3136d8;
}
.sider-child {
   background-color: red;
   width: 50px;
   height: 50px;
   margin: 0 auto;
   z-index: 100;  // 这里
   position: fixed; // 这里
   top: 10px;
   left: 10px;
}

看一眼谷歌效果~
在这里插入图片描述
然后!safari中如下图,父元素的hidden把子元素的fixed给盖住了
在这里插入图片描述

场景2的解决方案

1、去掉父元素的overflow:hidden,如果有需要,在子元素上添加
2、放弃使用left和top等进行布局,采用padding和margin将元素进行撑开,就避开了overflow的隐藏


http://www.niftyadmin.cn/n/1119721.html

相关文章

PTC被评为物联网应用支持平台市场份额领导者

近日&#xff0c;PTC&#xff08;纳斯达克代码&#xff1a;PTC&#xff09;宣布&#xff0c;被BCC Research评为物联网应用支持平台&#xff08;AEP&#xff09;市场份额领导者。凭借ThingWorx物联网平台&#xff0c;2015年PTC市场份额达到27%&#xff0c;是第二大供应商的两倍…

15 个最佳开源设计工具

1、Blender Blender是一套三维绘图及渲染软件。它具有跨平台的特性&#xff0c;支持FreeBSD&#xff0c;IRIX&#xff0c;GNU/Linux&#xff0c;Microsoft Windows&#xff0c;Mac OS X&#xff0c;Solaris&#xff0c;及SkyOS。 2、Inkspace Inkscape 是开源的矢量图形编辑软件…

突破Android P非SDK API限制的几种代码实现

前言 Android P对非SDK API的使用做了限制&#xff0c;导致在Android P上会出现一些状况。在很早前预览版本刚出来的时候&#xff0c;360团队就出了两篇文章。 Android P 调用隐藏API限制原理 以及 突破Android P(Preview 1)对调用隐藏API限制的方法 限制方式三种&#xff1a; …

遨翔在知识的海洋里----(onclick和jquery,click)

jquery function声明 <body><button onclick"test()">aa</button> </body><script src"https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <script>$(function() {function test() {console.log(…

ADT下开发环境的配置--个人配置啦 Eclipse Color Themes

一. Eclipse Color Themes的安装 首先 这个ADT没有Marketplace Client 需要装一个, 节选自: http://blog.csdn.net/liu372267001/article/details/11129729 Eclipse Marketplace是个插件应用商店&#xff0c;很实用的一个功能。 打开 eclipse&#xff0c;help--Eclipse Market…

mysql5.5 数据复制_mysql5.5.27主从复制

主从复制原理&#xff1a;1 复制架构图![](https://box.kancloud.cn/2016-03-29_56fa2a0c3a35d.jpg)2 初始化图![](https://box.kancloud.cn/2015-11-06_563c4ad5177e9.JPG)3 复制原理mysql使用3个线程来执行复制功能(其中1个在主服务器上&#xff0c;另两个在从服务器上)。当发…

django之异常错误2(Error was: No module named sqlite3.base)

具体错误代码为&#xff1a; C:\djangoweb\helloworld>manage.py syncdbTraceback (most recent call last): File "C:\djangoweb\helloworld\manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "C:\Python27\lib\site…

惠普企业服务助企业创新:感知社会 接近消费者

ZDNET至顶网CIO与应用频道 04月15日 人物访谈&#xff08;文/丁慧茹&#xff09;&#xff1a; 创新&#xff0c;是从工业文明开始一直到今天&#xff0c;所有企业都极力去追逐的目标。而创新在每个时期&#xff0c;又会呈现出不同的层面&#xff0c;原来企业更多重视的是所谓产…