gpt4 book ai didi

javascript - 任何确定透明背景颜色CSS的方法

转载 作者:行者123 更新时间:2023-12-02 18:52:00 25 4
gpt4 key购买 nike

这里已经写了很多关于在 javascript 中确定背景颜色的文章,但我还没有看到这个问题得到解决:假设我有一个空文档,没有其他东西,没有样式。 getcompatedstyle 对于这两个元素,背景颜色是“透明”。但那是什么颜色?用户选择的默认值,通常是白色,但也可以是任何颜色。那么有没有办法找出那是什么?看起来像是 DOM 中的一个缺陷。

最佳答案

查看 tricks this guy used.本质上,获得真实颜色的唯一方法是继续处理父元素,直到找到提供颜色定义的元素。

The methods above will return 'transparent' when called for the element with the ID someid, with two exceptions:

Safari will return "rgba(0, 0, 0, 0)", which means transparent, because the forth value stands for the opacity which is 0. Konqueror 3.5 will return "#000000" which is black and which is at the same time a known bug of Konqueror. I've tried to use getPropertyCSSValue, but that one is borked completely...

Now, if you want to retrieve the "real" background color of an element, you have to recursively move up the hierarchy until you find an element that doesn't have a transparent background. You have to stop however at document.body and assume white as background color.

关于javascript - 任何确定透明背景颜色CSS的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15721594/

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