[SCSS] Convert HEX to RGB

4,542 views
Skip to first unread message

Renan Couto

unread,
Jun 15, 2011, 9:00:36 AM6/15/11
to Haml
Is there a way to convert hex colors to RGB?

Алёна

unread,
Jun 15, 2011, 10:46:39 AM6/15/11
to ha...@googlegroups.com
Not sure if there is a built-in function, but you can get components of a color this way:
red($color);
green($color);
blue($color);

Here is the reference: http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#red-instance_method

2011/6/16 Renan Couto <renan...@gmail.com>

Chris Eppstein

unread,
Jun 15, 2011, 12:45:22 PM6/15/11
to ha...@googlegroups.com
I'd be interested to know why the output format matters. It seems like an implementation detail to me. Please continue this conversation on the sass mailing list. 

Hunt & pecked on my iPhone... Sorry if it's brief!
--
You received this message because you are subscribed to the Google Groups "Haml" group.
To post to this group, send email to ha...@googlegroups.com.
To unsubscribe from this group, send email to haml+uns...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/haml?hl=en.

Renan Couto

unread,
Jun 15, 2011, 1:01:35 PM6/15/11
to ha...@googlegroups.com
I see that there is this method: http://sass-lang.com/docs/yardoc/Sass/Script/Functions.html#rgba-instance_method
But it keeps rendering like this: rgba(#000000, .5)

--

Renan Couto

unread,
Jun 15, 2011, 1:15:11 PM6/15/11
to ha...@googlegroups.com
Sorry for the little detail.

The deal is: I created a mixin to handle background-colors with alpha, but IE8 and below (as usual) don't understand rgba.
So I end up with this code:

@mixin background-color($color, $path, $alpha: 1)
{
    $rgba: 'rgba(#' + $color + ', ' + $alpha + ')';
    $css-color: unquote($rgba);
       
    $filename: 'solid-' + $color + '-' + $alpha * 100 + '.png';
    $url: 'url(' + $path + $filename + ')';
   
    background-color: unquote($url);
    background-color: $css-color;
}

Then I called the mixin this way:
@include background-color(000000, .5);

And I expect to get the following output:
background-color: url('images/solid-000000-50.png');
background-color: rgba(0,0,0,.5);

But I keep getting rgba like this: rgba(#000000, .5)

I thought SASS would convert automatically hex color to rgb inside a rgba();

Chris Eppstein

unread,
Jun 15, 2011, 1:33:03 PM6/15/11
to ha...@googlegroups.com
This is the Haml list v


Hunt & pecked on my iPhone... Sorry if it's brief!
Reply all
Reply to author
Forward
0 new messages