Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS Sass Basics (retired) Speeding up Workflow with Sass Creating a Color Palette

Does the Color Palette variables within Sass work with RGBA values or just the Hexadecimal?

Can this be used for the other coloring styles rather than just Hexadecimal?

1 Answer

Mate Vegh
Mate Vegh
25,607 Points

Yes, they do! In Sass you can specify your colors in almost any color value: HEX, RGB, RGBA, HSL, HSLA

Sass:

$hex: #007FFF;
$rgb: rgb(0,127,255);
$rgba: rgba(0,127,255,.5);
$hsl: hsl(210,100%,50%);
$hsla: hsla(210,100%,50%,.5);

.element {
  color: $hex;
  color: $rgb;
  color: $rgba;
  color: $hsl;
  color: $hsla;
}

CSS:

.element {
  color: #007FFF;
  color: #007fff;
  color: rgba(0, 127, 255, 0.5);
  color: #007fff;
  color: rgba(0, 127, 255, 0.5);
}

Try it out on www.sassmeister.com

Adnan Pozegić
Adnan Pozegić
12,789 Points

Also keep an eye on that pesky IE support, from the reference:

IE filters require all colors include the alpha layer, and be in the strict format of #AABBCCDD. You can more easily convert the color using the ie_hex_str function. For example:

$translucent-red: rgba(255, 0, 0, 0.5);
$green: #00ff00;
div {
  filter: progid:DXImageTransform.Microsoft.gradient(enabled='false', startColorstr='#{ie-hex-str($green)}', endColorstr='#{ie-hex-str($translucent-red)}');
}