gpt4 book ai didi

html - 视频 z-index 变换旋转异常行为

转载 作者:行者123 更新时间:2023-11-27 22:50:10 25 4
gpt4 key购买 nike

我有一个场景。 canvas 上有各种组件。有视频图片和常用的资料

如下图,video(黑色的)会挡住下面的图片,但是图片的'z-index'为2,高于视频是 1

#root {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.css-wrap {
position: relative;
width: 100%;
height: 100%;
display: flex;
-webkit-box-pack: center;
justify-content: center;
-webkit-box-align: center;
align-items: center;
}
.css-rotate {
position: relative;
width: 211px;
height: 375px;
transform: rotate(90deg);
}
.css-pic {
/* backface-visibility: hidden; */
position: absolute;
display: block;
z-index: 2;
left: 43.07px;
top: 175.78px;
width: 124.8px;
height: 83.2px;
/* background: red; */
}
.css-video {
position: absolute;
display: block;
z-index: 1;
left: 0px;
top: 0px;
width: 210.94px;
height: 375px;
background: blue;
}
.css-overflow {
overflow: hidden;
position: relative;
width: 100%;
height: 100%;
color: rgb(0, 0, 0);
}
.css-height {
height: 100%;
}
.css-static {
position: static;
width: 100%;
height: 100%;
}
<html>
<body>
<div id="root">
<div class="css-wrap">
<div class="css-rotate">
<div class="css-overflow">
<div class="css-pic">
<div class="css-height">
<img class="css-static" src="https://www.gravatar.com/avatar/43111ebfc98a0b559c4a1dc31b6e39f6?s=32&d=identicon&r=PG">
</div>
</div>
<div class="css-video">
<div class="css-height">
<video class="css-static" playsinline="" webkit-playsinline="true" x5-playsinline="" x5-video-player-type="h5" x5-video-player-fullscreen="true" preload="auto">
<source src="http://vjs.zencdn.net/v/oceans.mp4">
</video>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

查了一些资料,发现可能跟transform导致的context有关,但稍微修改一下,就更加迷糊了。

至少有三种方法可以使图片工作:

<强>1。去掉父级的overflow:hidden(但是这个是不可移除的,让人迷惑)

#root {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.css-wrap {
position: relative;
width: 100%;
height: 100%;
display: flex;
-webkit-box-pack: center;
justify-content: center;
-webkit-box-align: center;
align-items: center;
}
.css-rotate {
position: relative;
width: 211px;
height: 375px;
transform: rotate(90deg);
}
.css-pic {
/* backface-visibility: hidden; */
position: absolute;
display: block;
z-index: 2;
left: 43.07px;
top: 175.78px;
width: 124.8px;
height: 83.2px;
/* background: red; */
}
.css-video {
position: absolute;
display: block;
z-index: 1;
left: 0px;
top: 0px;
width: 210.94px;
height: 375px;
background: blue;
}
.css-overflow {

position: relative;
width: 100%;
height: 100%;
color: rgb(0, 0, 0);
}
.css-height {
height: 100%;
}
.css-static {
position: static;
width: 100%;
height: 100%;
}
<html>
<body>
<div id="root">
<div class="css-wrap">
<div class="css-rotate">
<div class="css-overflow">
<div class="css-pic">
<div class="css-height">
<img class="css-static" src="https://www.gravatar.com/avatar/43111ebfc98a0b559c4a1dc31b6e39f6?s=32&d=identicon&r=PG">
</div>
</div>
<div class="css-video">
<div class="css-height">
<video class="css-static" playsinline="" webkit-playsinline="true" x5-playsinline="" x5-video-player-type="h5" x5-video-player-fullscreen="true" preload="auto">
<source src="http://vjs.zencdn.net/v/oceans.mp4">
</video>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

<强>2。将rotate的 Angular 改成0或20等小 Angular (这是否意味着它可能不是transform引起的?)

#root {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.css-wrap {
position: relative;
width: 100%;
height: 100%;
display: flex;
-webkit-box-pack: center;
justify-content: center;
-webkit-box-align: center;
align-items: center;
}
.css-rotate {
position: relative;
width: 211px;
height: 375px;
transform: rotate(30deg);
}
.css-pic {
/* backface-visibility: hidden; */
position: absolute;
display: block;
z-index: 2;
left: 43.07px;
top: 175.78px;
width: 124.8px;
height: 83.2px;
/* background: red; */
}
.css-video {
position: absolute;
display: block;
z-index: 1;
left: 0px;
top: 0px;
width: 210.94px;
height: 375px;
background: blue;
}
.css-overflow {
overflow: hidden;
position: relative;
width: 100%;
height: 100%;
color: rgb(0, 0, 0);
}
.css-height {
height: 100%;
}
.css-static {
position: static;
width: 100%;
height: 100%;
}
<html>
<body>
<div id="root">
<div class="css-wrap">
<div class="css-rotate">
<div class="css-overflow">
<div class="css-pic">
<div class="css-height">
<img class="css-static" src="https://www.gravatar.com/avatar/43111ebfc98a0b559c4a1dc31b6e39f6?s=32&d=identicon&r=PG">
</div>
</div>
<div class="css-video">
<div class="css-height">
<video class="css-static" playsinline="" webkit-playsinline="true" x5-playsinline="" x5-video-player-type="h5" x5-video-player-fullscreen="true" preload="auto">
<source src="http://vjs.zencdn.net/v/oceans.mp4">
</video>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

<强>3。如果你删除了video元素或者display:none,你会发现显示电平是正确的(是不是说明问题出在video元素上)

#root {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.css-wrap {
position: relative;
width: 100%;
height: 100%;
display: flex;
-webkit-box-pack: center;
justify-content: center;
-webkit-box-align: center;
align-items: center;
}
.css-rotate {
position: relative;
width: 211px;
height: 375px;
transform: rotate(90deg);
}
.css-pic {
/* backface-visibility: hidden; */
position: absolute;
display: block;
z-index: 2;
left: 43.07px;
top: 175.78px;
width: 124.8px;
height: 83.2px;
/* background: red; */
}
.css-video {
position: absolute;
display: block;
z-index: 1;
left: 0px;
top: 0px;
width: 210.94px;
height: 375px;
background: blue;
}
.css-overflow {
overflow: hidden;
position: relative;
width: 100%;
height: 100%;
color: rgb(0, 0, 0);
}
.css-height {
height: 100%;
}
.css-static {
position: static;
width: 100%;
height: 100%;
}
<html>
<body>
<div id="root">
<div class="css-wrap">
<div class="css-rotate">
<div class="css-overflow">
<div class="css-pic">
<div class="css-height">
<img class="css-static" src="https://www.gravatar.com/avatar/43111ebfc98a0b559c4a1dc31b6e39f6?s=32&d=identicon&r=PG">
</div>
</div>
<div class="css-video">
<div class="css-height">

</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

经过这三种猜测,是不是video、absolute、rotate的混合作用导致'z-index'表现异常?

希望有人能给我一个答案。谢谢。

最佳答案

你只需将视频的 z-index 设置为 -1 这样我就可以在你的所有内容后面设置上面的上下文 z-index 根据要求

Here is updated snippet

#root {
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
.css-wrap {
position: relative;
width: 100%;
height: 100%;
display: flex;
-webkit-box-pack: center;
justify-content: center;
-webkit-box-align: center;
align-items: center;
}
.css-rotate {
position: relative;
width: 211px;
height: 375px;
transform: rotate(90deg);
}
.css-pic {
position: absolute;
display: block;
z-index: 2;
left: 50%;
top: 50%;
width: 124.8px;
height: 83.2px;
transform: translate(-50%, -50%);
}
.css-video {
position: absolute;
display: block;
z-index: -1;
left: 0px;
top: 0px;
width: 210.94px;
height: 375px;
background: blue;
}
.css-overflow {
overflow: hidden;
position: relative;
width: 100%;
height: 100%;
color: rgb(0, 0, 0);
}
.css-height {
height: 100%;
}
.css-static {
position: static;
width: 100%;
height: 100%;
}
<html>
<body>
<div id="root">
<div class="css-wrap">
<div class="css-rotate">
<div class="css-overflow">
<div class="css-pic">
<div class="css-height">
<img class="css-static" src="https://www.gravatar.com/avatar/43111ebfc98a0b559c4a1dc31b6e39f6?s=32&d=identicon&r=PG">
</div>
</div>
<div class="css-video">
<div class="css-height">
<video class="css-static" playsinline="" webkit-playsinline="true" x5-playsinline="" x5-video-player-type="h5" x5-video-player-fullscreen="true" preload="auto">
<source src="http://vjs.zencdn.net/v/oceans.mp4">
</video>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
我还将图像设置为 video

的中心

关于html - 视频 z-index 变换旋转异常行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59483408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com