css - LESScss converting rgba to hex? how to nest color variables into a mixin? -
does lesscss convert rgba colors hex values?
i trying create mixin, say, .color, allows pass in color variable defined, , want in rgba.
this doesn't work, here's idea:
.bgcolor(@colorvariable,@alpha) { background-color: @colorvariable + rgba(0, 0, 0, @alpha); }
where @colorvariable
be, @blue: rgb(17,55,76);
or @green: rgb(125,188,83);
etc.
i want define bunch of these variables, , able pass them in .bgcolor
or .color
mixin , change alpha transparency on fly.
i feel should possible, missing something. -right now, code ever outputs hex color value, no matter input.- if pass in @alpha value of 1, outputs hex color value. @alpha values less 1 force browser show me rgba value. that's solved.
now--how pass in rgb , parts separately predefined variable?
turns out, less has hsla functions built in (see less color functions). help, here's discovered:
@dkblue: #11374c; .colorize_bg(@color: @white, @alpha: 1) { background: hsla(hue(@color), saturation(@color), lightness(@color), @alpha);}
then use mixin:
section {.colorize_bg(@dkblue,1);}
so pass in color variable @dkblue
, less' functions hue(@color)
take @dkblue
, pull out hue, saturation, , lightness values. can pass in alpha define in mixin.
then can use in other ways, define transparent borders. adding background-clip: padding-box;
.colorize_bg
ensure borders show outside of bg box color (isn't css3 magical?) can redefine mixin work border color:
.colorize_border(@color: @white, @alpha: 1) {border-color: hsla(hue(@color), saturation(@color), lightness(@color), @alpha);}
and give section
border width, style, , define color via mixin:
section {border-width: 0 10px; border-style: solid; .colorize_border(@dkblue, .5);
and you'll magical, shiny transparent borders, so: http://i.stack.imgur.com/4jskr.png
Comments
Post a Comment