LESScss converting rgba to hex? how to nest color variables into a mixin?

后端 未结 3 1865
你的背包
你的背包 2021-01-31 05:00

Does LESScss convert all rgba colors to hex values?

I am trying to create a mixin, say, .color, that allows you to pass in a color variable previously defined, and I wan

3条回答
  •  忘了有多久
    2021-01-31 05:44

    You don't need to convert to hsla either so you won't need a white value

    .hexBackgroundToRGBA(@color,@alpha){
      @myred:red(@color);
      @mygreen:green(@color);
      @myblue:blue(@color);
      background-color: @color;
      background-color: rgba(@myred,@mygreen,@myblue,@alpha);
    }
    

    You'll have to write a few of these mixins in you need to set stuff other than the background-color property set but that's the idea. Just call it like this:

    #selector{  .hexBackgroundToRGBA(@gray, 0.8); }
    

    That will take whatever color val you have in the @gray variable and output a cross browser solution at 80% transparency with a solid color fallback for browsers that don't support rgba().

提交回复
热议问题