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

前端 未结 5 2215
暖寄归人
暖寄归人 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:29

    The rgba function doesn't work on color with no transparency, it returns an hex again. After all, it's not meant to transform hex to rgba, we're just making profit out of hex doesn't allow alpha (yet).

    rgba(#fff, 1) // returns #fff
    

    So, I made al little functions that buils the rgb string. I don't need to deal with transparencies for now.

    @function toRGB ($color) {
        @return "rgb(" + red($color) + ", " + green($color) + ", " + blue($color)+ ")";
    }
    

提交回复
热议问题