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

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

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

问题

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

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. body {
  10. background-color: #aeccab;
  11. }
  12. .numWrap {
  13. font-size: 80pt;
  14. width: 500px;
  15. height: 500px;
  16. display: flex;
  17. border: 1px solid rgb(255, 0, 0);
  18. flex-direction: column;
  19. align-items: center;
  20. overflow: hidden;
  21. position: relative;
  22. border-radius: 2rem;
  23. z-index: 25;
  24. }
  25. .numWrap-shadow {
  26. position: absolute;
  27. border-radius: 2rem;
  28. border: 1px solid rgb(67, 29, 204);
  29. mix-blend-mode: multiply;
  30. width: 100%;
  31. height: 100%;
  32. box-shadow: inset 18px 18px 36px #a1a1a1c8;
  33. z-index: 19;
  34. }
  35. .time,
  36. .time-alt {
  37. color: rgba(76, 85, 71, 0.876);
  38. border: 1px dashed rgb(230, 0, 255);
  39. height: 100%;
  40. width: 100%;
  41. font-size: 300%;
  42. text-align: center;
  43. align-items: center;
  44. transition: linear;
  45. transition-duration: 200ms;
  46. transition-property: transform;
  47. overflow: hidden;
  48. position: absolute;
  49. display: flex;
  50. justify-content: center;
  51. transform: translateY(0%);
  52. will-change: transform;
  53. background-color: #dedede;
  54. box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
  55. }
  56. </style>
  57. </head>
  58. <body>
  59. <div class="numWrap hoursWrap">
  60. <div class="numWrap-shadow"></div>
  61. <div class="time-alt time--hours inactive"><span>00</span></div>
  62. <div class="time time--hours"><span>00</span></div>
  63. </div>
  64. </body>
  65. </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.

  1. &lt;!DOCTYPE html&gt;
  2. &lt;html lang=&quot;en&quot;&gt;
  3. &lt;head&gt;
  4. &lt;meta charset=&quot;UTF-8&quot;&gt;
  5. &lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edge&quot;&gt;
  6. &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
  7. &lt;title&gt;Document&lt;/title&gt;
  8. &lt;style&gt;
  9. body {
  10. background-color: #aeccab;
  11. }
  12. .numWrap {
  13. font-size: 80pt;
  14. width: 500px;
  15. height: 500px;
  16. display: flex;
  17. border: 1px solid rgb(255, 0, 0);
  18. flex-direction: column;
  19. align-items: center;
  20. overflow: hidden;
  21. position: relative;
  22. border-radius: 2rem;
  23. z-index: 25;
  24. }
  25. .numWrap-shadow {
  26. position: absolute;
  27. /*top: 0;
  28. bottom: 0;
  29. border-radius: 2rem;
  30. /*background: linear-gradient(to right bottom,
  31. rgba(226, 219, 205, 0.753),
  32. rgba(255, 255, 255, 0.1));*/
  33. /*left: 0;
  34. backface-visibility: hidden;
  35. right: 0;*/
  36. border-radius: 2rem;
  37. border: 1px solid rgb(67, 29, 204);
  38. mix-blend-mode: multiply;
  39. width: 100%;
  40. height: 100%;
  41. box-shadow: inset 18px 18px 36px #a1a1a1c8;
  42. z-index: 19;
  43. }
  44. .time,
  45. .time-alt {
  46. color: rgba(76, 85, 71, 0.876);
  47. border: 1px dashed rgb(230, 0, 255);
  48. height: 100%;
  49. width: 100%;
  50. font-size: 300%;
  51. text-align: center;
  52. align-items: center;
  53. transition: linear;
  54. transition-duration: 200ms;
  55. transition-property: transform;
  56. overflow: hidden;
  57. position: absolute;
  58. display: flex;
  59. justify-content: center;
  60. transform: translateY(0%);
  61. will-change: transform;
  62. background-color: #dedede;
  63. box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
  64. }
  65. &lt;/style&gt;
  66. &lt;/head&gt;
  67. &lt;body&gt;
  68. &lt;div class=&quot;numWrap hoursWrap&quot;&gt;
  69. &lt;div class=&quot;numWrap-shadow&quot;&gt;&lt;/div&gt;
  70. &lt;div class=&quot;time-alt time--hours inactive&quot;&gt;&lt;span&gt;00&lt;/span&gt;&lt;/div&gt;
  71. &lt;div class=&quot;time time--hours&quot;&gt;&lt;span&gt;00&lt;/span&gt;&lt;/div&gt;
  72. &lt;/div&gt;
  73. &lt;/body&gt;
  74. &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:

确定