Sass/Compass - Convert Hex, RGB, or Named Color to RGBA

前端 未结 5 2224
暖寄归人
暖寄归人 2020-12-04 14:59

This may be Compass 101, but has anyone written a mixin which sets the alpha value of a color? Ideally, I would like the mixin to take any form of color definition, and app

5条回答
  •  醉酒成梦
    2020-12-04 15:48

    Use the rgba function built into Sass

    Sets the opacity of a color.

    Examples:

    rgba(#102030, 0.5) => rgba(16, 32, 48, 0.5)
    rgba(blue, 0.2) => rgba(0, 0, 255, 0.2)

    Parameters:
    (Color) color
    (Number) alpha — A number between 0 and 1

    Returns:
    (Color)

    Code:

    rgba(#ff0000, 0.5); // Output is rgba(255,0,0,0.5);
    

提交回复
热议问题