gpt4 book ai didi

css - "opacity"和 "filter: opacity()"有什么区别

转载 作者:技术小花猫 更新时间:2023-10-29 10:13:26 24 4
gpt4 key购买 nike

我们大多数人都知道简单的 opacity CSS 规则,但最近我偶然发现了 filter,它可以将 opacity(amount) 作为它的值- 除其他事项外。但这两者到底有什么区别呢?

最佳答案

filter: opacity() is similar to the more established opacity property; the difference is that with filter: opacity(), some browsers provide hardware acceleration for better performance. Negative values are not allowed.

filter: opacity() applies transparency. A value of 0% is completely transparent. A value of 100% leaves the input unchanged. Values between 0% and 100% are linear multipliers on the effect. This is equivalent to multiplying the input image samples by amount. If the “amount” parameter is missing, a value of 100% is used.

来源:https://css-tricks.com/almanac/properties/f/filter/

/*
* -----------
* filter: opacity([ <number> or <percentage> ])
* -----------
*/

.filter-opacity {
filter: opacity(0.3);
height: 5rem;
width: 5rem;
background-color: mediumvioletred;
}

/*
* -----------
* standard opacity
* -----------
*/

.just-opacity {
opacity: 0.3;
height: 5rem;
width: 5rem;
background-color: lawngreen;
}
<div class="filter-opacity">
filter-opacity
</div>

<div class="just-opacity">
just-opacity
</div>

关于css - "opacity"和 "filter: opacity()"有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20310219/

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