混合混合模式在溢出和行为不一致。

huangapple go评论58阅读模式
英文:

Inconsistent behaviour when using mix-blend-mode with overflow and

问题

我在Safari中遇到了一个奇怪的问题,似乎CSS属性mix-blend-mode会导致父元素(.numWrap)的overflow:hidden停止起作用。下面是我分离出来展示这个问题的一些CSS/HTML示例:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
    
    body {
        background-color: #aeccab;
    }

    .numWrap {
        font-size: 80pt;
        width: 500px;
        height: 500px;
        display: flex;
        border: 1px solid rgb(255, 0, 0);
        flex-direction: column;
        align-items: center;
        overflow: hidden;
        position: relative;
        border-radius: 2rem;
        z-index: 25;
    }

    .numWrap-shadow {
        position: absolute;
        border-radius: 2rem;
        border: 1px solid rgb(67, 29, 204);
        mix-blend-mode: multiply;
        width: 100%;
        height: 100%;
        box-shadow: inset 18px 18px 36px #a1a1a1c8;
        z-index: 19;
    }

    .time,
    .time-alt {
        color: rgba(76, 85, 71, 0.876);
        border: 1px dashed rgb(230, 0, 255); 
        height: 100%;
        width: 100%;
        font-size: 300%;
        text-align: center;
        align-items: center;
        transition: linear;
        transition-duration: 200ms;
        transition-property: transform;
        overflow: hidden;
        position: absolute;
        display: flex;
        justify-content: center;
        transform: translateY(0%);
        will-change: transform;
        background-color: #dedede;
        box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
    }
    </style>
</head>
<body>
<div class="numWrap hoursWrap">
    <div class="numWrap-shadow"></div>
    <div class="time-alt time--hours inactive"><span>00</span></div>
    <div class="time time--hours"><span>00</span></div>
</div>
</body>
</html>

在开发工具中禁用mix-blend-mode会恢复到预期的行为。这个问题在Chrome和Firefox中并不会出现(我进行了大部分的实际测试)。

英文:

I'm experiencing a strange result in Safari where it seems the CSS attribute mix-blend-mode seems to stop overlow:hidden of the parent (.numWrap) div from working. The example below is a snippet of the overall project, which is a flip-style timer app.

The use of mix-blend-mode is preferred as allows the shading to more naturally fall on the card below.

Behaviour in Safari (all devices)

Behaviour in Chrome

See below some CSS/HTML I've isolated, exhibiting this behaviour.


&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
&lt;title&gt;Document&lt;/title&gt;
&lt;style&gt;
body {
background-color: #aeccab;
}
.numWrap {
font-size: 80pt;
width: 500px;
height: 500px;
display: flex;
border: 1px solid rgb(255, 0, 0);
flex-direction: column;
align-items: center;
overflow: hidden;
position: relative;
border-radius: 2rem;
z-index: 25;
}
.numWrap-shadow {
position: absolute;
/*top: 0;
bottom: 0;
border-radius: 2rem;
/*background: linear-gradient(to right bottom,
rgba(226, 219, 205, 0.753),
rgba(255, 255, 255, 0.1));*/
/*left: 0;
backface-visibility: hidden;
right: 0;*/
border-radius: 2rem;
border: 1px solid rgb(67, 29, 204);
mix-blend-mode: multiply;
width: 100%;
height: 100%;
box-shadow: inset 18px 18px 36px #a1a1a1c8;
z-index: 19;
}
.time,
.time-alt {
color: rgba(76, 85, 71, 0.876);
border: 1px dashed rgb(230, 0, 255); 
height: 100%;
width: 100%;
font-size: 300%;
text-align: center;
align-items: center;
transition: linear;
transition-duration: 200ms;
transition-property: transform;
overflow: hidden;
position: absolute;
display: flex;
justify-content: center;
transform: translateY(0%);
will-change: transform;
background-color: #dedede;
box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class=&quot;numWrap hoursWrap&quot;&gt;
&lt;div class=&quot;numWrap-shadow&quot;&gt;&lt;/div&gt;
&lt;div class=&quot;time-alt time--hours inactive&quot;&gt;&lt;span&gt;00&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;time time--hours&quot;&gt;&lt;span&gt;00&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

I've worked through all parts of the relevant CSS to identify the issue. Disabling the mix-blend-mode within DevTools returns to the expected behaviour. This is not an issue in Chrome or Firefox (where most of my live testing has occured).

答案1

得分: 0

如果有人遇到这个问题,我已经解决了。我认为这与WebKit奇怪地处理堆叠上下文有关(尽管我不太清楚这意味着什么)。

为了解决这个问题,我将 numWrap-shadownumWrap div 中移出,并创建了一个新的容器 div 来容纳它们,将必要的属性转移过去。

如果有进一步的问题,我愿意尽力提供更多解答!

英文:

If anyone encounters this issue, I have solved it. I think it has something to do with WebKit handling stacking contexts oddly (though I'm not clear on what that means).

To solve this, I moved numWrap-shadow out of the numWrap div and created a new container div for both, transferring the necessary attributes.

If anyone has further questions, happy to expand where I can!

huangapple
  • 本文由 发表于 2023年2月27日 05:02:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75574994.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定