Sass color function


Release date:2024-03-01 Update date:2024-03-01 Editor:admin View counts:159

Label:

Sass color function

The Sass color function can be divided into three parts: color setting, color acquisition and color operation.

The following table lists the color functions for Sass:

Sass color setting

Function

Description & example

rgb(red, green, blue)

Create a Red-Green-Blue (RGB) color. Where R is “red” for red, G is “green” green, and B is “blue” blue.

Example: rgb (0,0,255)

rgba(red, green, blue, alpha)

Create a color based on red, green, blue, and transparency values.

Example: rgba (0,0,255,0.3)

hsl(hue, saturation, lightness)

Create a color from the values of hue, saturation, and luminance (lightness).

Example: hsl (120,100%, 50%); // green hsl (120,100%, 75%); // light greenhsl (120,100%, 25%); // dark green hsl (120,60%, 70%); // soft green

hsla(hue, saturation, lightness, alpha)

Create a color from the values of hue, saturation, luminance (lightness), and transparency (alpha).

Example: hsl (120,100%, 50%, 0.3); // Green with transparency hsl (120,100%, 75%, 0.3); // Light green with transparency

grayscale(color)

Turning a color to gray is equivalent to desaturate (color,100%).

Example: grayscale (# 7fffd4); result: # c6c6c6

complement(color)

Returns a complementary color equivalent to adjust-hue ($color,180deg).

Example: complement (# 7fffd4); result: # ff7faa

invert(color, weight)

Returns an inverted color with red, green, and blue values reversed, while the transparency remains the same.

Example: invert (white); result: black

Sass color acquisition

Function

Description & example

red(color)

Gets the red value (0-255) from a color.

Example: red (# 7fffd4); result: 127red (red); result: 255th

green(color)

Gets the green value (0-255) from a color.

Example: green (# 7fffd4); result: 255green (blue); result: 0

blue(color)

Gets the blue value from a color (0-255).

Example: blue (# 7fffd4); result: 212 blue (blue); result: 255

hue(color)

Returns the angle value of the color in the HSL color value (0deg-255deg).

Example: hue (# 7fffd4); result: 160deg

saturation(color)

Gets the saturation value of a color (0%-100%).

Example: saturation (# 7fffd4); result: 100%

lightness(color)

Gets the luminance value of a color (0%-100%).

Example: lightness (# 7fffd4); result: 74.9%

alpha(color)

Returns the alpha channel of color as a number between 0 and 1.

Example: alpha (# 7fffd4); result: 1

opacity(color)

Gets the color transparency value (0-1).

Example: opacity (rgba (127,255,212,0.5); result: 0.5

Sass color operation

Function

Description & example

mix(color1, color2, weight)

Mix the two colors. The weight parameter must be 0 to 100%. The default weight is 50%, indicating that the new color takes 50% of the color values of color1 and color2. If weight is 25%, that means the new color is the sum of 25% color1 and 75% color2.

adjust-hue(color, degrees)

Create a new color by changing the hue value of a color (- 360deg-360deg).

Example: adjust-hue (# 7fffd4, 80deg); result: # 8080ff

adjust-color(color, red, green, blue, hue, saturation, ightness, alpha)

This function adjusts one or more attribute values of a given color, including the color value parameters of RGB and HSL colors, as well as the values of the alpha channel. The adjustment of these attribute values depends on the passed-in key value parameters, which are then added and subtracted from the corresponding color values of a given color.

Example: adjust-color (# 7fffd4, blue: 25); result:

change-color(color, red, green, blue, hue, saturation, lightness, alpha)

Similar to the adjust-color above, except that the parameters passed in this function will directly replace the original value without doing any operations.

Example: change-color (# 7fffd4, red: 255); result: # ffffd4

scale-color(color, red, green, blue, saturation, lightness, alpha)

Another practical color adjustment function. Adjust-color simply adds or subtracts from its own color parameters through the passed parameters, whichmay sometimes cause cumulative value overflows. Of course, the function will keep the result within a valid threshold. The scale-color function avoids this situation and allows the parameters to be effectively adjusted within the threshold range without having to worry about overflow.

For example, the luminance lightness of a color is between 0% and 100%. If you perform scale-color ($color, $lightness: 40%), the brightness of the color will increase by (100-original) × 40%.

Another example is to execute scale-color ($color, $lightness:-40%), indicating that the brightness of this color will be reduced by as much as (original value-0) x 40%.

The values of all passed parameters range from 0% to 100%, and the parameters passed by RGB and HSL cannot conflict.

scale-color(hsl(120, 70%, 80%), $lightness: 50%) => hsl(120, 70%, 90%)
scale-color(rgb(200, 150, 170), $green: -40%, $blue: 70%) => rgb(200, 90, 229)
scale-color(hsl(200, 70%, 80%), $saturation: -90%, $alpha: -30%) => hsla(200, 7%, 80%, 0.7)

rgba(color, alpha)

Create a color based on red, green, blue, and transparency values.

Example: rgba (# 7fffd4, 30%); result: rgba (127,255,212,0.3)

lighten(color, amount)

Create a new color by changing the luminance value of the color (0%-100%) to brighten the color.

darken(color, amount)

Darken the color and create a new color by changing the luminance value of the color (0%-100%).

saturate(color, amount)

Increase the color saturation of incoming colors. Equivalent to adjust-color (color, saturation: amount)

desaturate(color, amount)

Lower the saturation of a color to produce a new color value. Similarly, the saturation ranges from 0% to 100%. Equivalent to adjust-color (color, saturation:-amount)

opacify(color, amount)

Reduce the transparency of the color, with a value of 0-1. Equivalent to adjust-color (color, alpha: amount)

fade-in(color, amount)

Reduce the transparency of the color, with a value of 0-1. Equivalent to adjust-color (color, alpha: amount)

transparentize(color, amount)

Improve the transparency of the color, with a value between 0 and 1. Equivalent to adjust-color (color, alpha:-amount)

fade-out(color, amount)

Improve the transparency of the color, with a value between 0 and 1. Equivalent to adjust-color (color, alpha:-amount)

Powered by TorCMS (https://github.com/bukun/TorCMS).