gpt4 book ai didi

CSS Stylus 颜色函数,单位敏感性如何工作?

转载 作者:行者123 更新时间:2023-11-28 17:28:10 25 4
gpt4 key购买 nike

我在 Stylus CSS 预处理器语言的文档中读到,颜色函数单位敏感。例如:

darken(color, amount)

Darken the given color by amount.This function is unit-sensitive, for example supporting percentages as shown below.

下面是与上述功能配套的代码示例:

darken(#D62828, 30)
// => #551010

darken(#D62828, 30%)
// => #961c1c

我不明白的是,第一个示例(数量为 30)是如何计算出来的。数量30代表什么单位。

最佳答案

是的,这远非直观,但如果您查看源代码,您会发现:

  1. darken bif像这样调用 adjust bif:adjust(color, 'lightness', - amount)

  2. adjust bif对于百分比和其他单位有不同的行为:

    • 当有一个像 30 这样的单位时,它会通过从颜色的亮度中减少给定的量来改变颜色的亮度。
    • 当有百分比时,它会根据初始颜色亮度的给定百分比降低其亮度。

关于CSS Stylus 颜色函数,单位敏感性如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26719490/

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