简体   繁体   English

Background-color:rgba() - Safari 透明度 css 错误

[英]Background-color:rgba() - Safari transparency css bug

I'm using rgba(0,0,0,0.5) as background-color property, it works fine in every browser except safari version 12.0.2 on my Friend's macbook I'm also using https://www.lambdatest.com/ to test browser compatibility, it works just fine on their safari browsers, simply everywhere except on my friends macbook, any ides what might be the problem ?我使用 rgba(0,0,0,0.5) 作为背景颜色属性,它在除我朋友的 macbook 上的 safari 版本 12.0.2 之外的所有浏览器中都能正常工作我也在使用https://www.lambdatest.com /来测试浏览器的兼容性,它在他们的 safari 浏览器上工作得很好,除了我朋友的 macbook 之外的任何地方,任何 ide 可能是什么问题?

I can not use HEX code and then opacity rule, because this also affects buttons on top of this div, also only rgba is not working on my friends laptop, rgb or hex does, but i need to use rgba because of opacity.我不能使用 HEX 代码和不透明度规则,因为这也会影响这个 div 顶部的按钮,也只有 rgba 不能在我朋友的笔记本电脑上工作,rgb 或 hex 可以,但由于不透明度,我需要使用 rgba。

Compatibility tables says that rgba is supported on safari 2.0+ so I see no reason why it should not not working on safari 12.0.2兼容性表说 safari 2.0+ 支持 rgba,所以我看不出它为什么不能在 safari 12.0.2 上运行

Any ideas what might cause this ?有什么想法可能导致这种情况吗?

 .initialPanel { overflow: hidden; width: 900px; height: 130px; background-color: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center } .initialPanelWrap { position: absolute; width: 100%; bottom: 35%; display: flex; justify-content: center } .HpButtonGreen { height: 60px; width: 360px; background-color: #1e983e!important; color: white; border: none; cursor: pointer; } .HpButtonGreen:hover { background-color: #0F792B!important; -webkit-transition: background-color 300ms linear; -ms-transition: background-color 300ms linear; transition: background-color 300ms linear; }
 <div class="initialPanelWrap"> <div class="initialPanel"> <div class="riadok"> <div class="butcol margin-right-30"><button class="HpButtonGreen" type="button"></button></div> <div class="butcol"><button class="HpButtonGreen" type="button"></button></div> </div> </div> </div>

Ok, now this is really weird but when I used rgba(0, 0, 0, 0.5) the background was not visible at all but when I used rgba(0,0,0,0.51) or 0.49 it was working, just the exact 50% opacity on rgba was not showing at all.好的,现在这真的很奇怪,但是当我使用 rgba(0, 0, 0, 0.5) 时,背景根本不可见,但是当我使用 rgba(0,0,0,0.51) 或 0.49 时,它正在工作,只是rgba 上的 50% 不透明度根本没有显示。 I have no idea what was causing this.我不知道是什么原因造成的。

EDIT:编辑:

Safari version 12.0.2 sometimes have problem rendering opacity with rgba when you use "0.5" but when you use ".5" (without zero) it's okay.当您使用“0.5”时,Safari 12.0.2 版有时会在使用 rgba 渲染不透明度时出现问题,但是当您使用“.5”(不带零)时,这没关系。 I have no idea what is causing this and maybe it's already fixed in newer versions of safari.我不知道是什么导致了这种情况,也许它已经在较新版本的 safari 中修复了。

At the time of writing this answer, iOS 12 usage is still at 5% - which is still considerable enough to share my CSS-only solution to this undocumented RGBA opacity bug.在撰写此答案时,iOS 12 的使用率仍为 5% - 这仍然足以分享我对这个未记录的 RGBA 不透明度错误的纯 CSS 解决方案。 I hope my solution helps future visitors support older versions of iOS without scratching their heads too much.我希望我的解决方案可以帮助未来的访问者支持旧版本的 iOS,而不会过多地摸不着头脑。 This S/O post seems to be the only trace on the Internet regarding this bug.这篇 S/O 帖子似乎是 Internet 上有关此错误的唯一踪迹。

My case: I have an industrial website design where all my RGBA opacity values are rendered exactly twice as opaque on iOS 12 and below.我的情况:我有一个工业网站设计,其中我所有的 RGBA 不透明度值在 iOS 12 及更低版本上都呈现为不透明的两倍。 The design is rather simple, and the only non-standards (unstable) CSS I use is -webkit-mask-image on a few parent elements for fading corners.设计相当简单,我使用的唯一非标准(不稳定)CSS 是一些父元素上的-webkit-mask-image用于淡化角落。 I use rgba(200,200,200,0.5) syntax as flat backgrounds and also in linear gradients.我使用rgba(200,200,200,0.5)语法作为平面背景和线性渐变。 My iOS 12 test devices were iPhone 8 Plus and iPhone 6. My iOS 13 test devices were iPhone XS Max and iPhone 7. I also confirmed that an iPhone 4S running iOS 9 also rendered twice as opaque.我的 iOS 12 测试设备是 iPhone 8 Plus 和 iPhone 6。我的 iOS 13 测试设备是 iPhone XS Max 和 iPhone 7。我还确认运行 iOS 9 的 iPhone 4S 也呈现两倍的不透明。

I tried manipulating the alpha values as described above, but that didn't solve my problem on any of my test devices.我尝试如上所述操作 alpha 值,但这并没有解决我在任何测试设备上的问题。

The only way I could get the opacities to match across all the iPhones was to duplicate the CSS rule set, cut the alpha values in half, and target iOS 12 and below.我可以让所有 iPhone 的不透明度匹配的唯一方法是复制 CSS 规则集,将 alpha 值减半,并以 iOS 12 及更低版本为目标。 At 5% mobile usage, I did not want to have to write JavaScript user agent detection just for this weird bug, so I did some digging to create a CSS selector for iOS 12 and below.在 5% 的移动使用率下,我不想仅仅为了这个奇怪的错误而编写 JavaScript 用户代理检测,所以我做了一些挖掘来为 iOS 12 及更低版本创建一个 CSS 选择器。

I placed my half-as-opaque backgrounds within this at-rule:我将半透明的背景放在了这个规则中:

@supports (-webkit-touch-callout: none) and (not (line-break: anywhere)) {

  #bugfix { background: rgba(200,200,200,0.25); }  /* Divide last value by 2 */

}

Explanation: @supports (-webkit-touch-callout: none) targets Apple Webkit so our altered RGBA values only apply to Apple products, then line-break: anywhere is only available on iOS 13 and higher, so we negate that to target iOS 12.x and lower.解释: @supports (-webkit-touch-callout: none)以 Apple Webkit 为目标,因此我们更改后的 RGBA 值仅适用于 Apple 产品,然后line-break: anywhere仅适用于 iOS 13 及更高版本,因此我们否定它以针对 iOS 12.x 及更低版本。 Source: Safari 13.1 Release Notes来源: Safari 13.1 发行说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM