Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does light($color,50%) parse to white?

Tags:

css

sass

This sass snippet:

$red: #f00

$lightred: lighten($red, 50%)

body
  background: $lightred

Is parsed to:

body {
  background: white; }

If you instead do 45% instead of 50%, it seems to work as expected:

$lightred2: lighten($red, 45%)
...
background-color: #ffe5e5

Why is this turning into white instead of the expected 50% of red?

You can see it in action here http://tinkerbin.com/OefelPoi

(Note - the save function seems to have a bug, on the css area, select Sass Old Syntax again, and rerun)

Update -

Ends up what I wanted was to mix in white with the original color to get a tinted shade:

mix($color,white, 10%)
like image 554
asawyer Avatar asked Mar 31 '12 21:03

asawyer


People also ask

How do I change colors in SCSS?

Sass Set Color Functions An RGB color value is specified with: rgb(red, green, blue). Each parameter defines the intensity of that color and can be an integer between 0 and 255, or a percentage value (from 0% to 100%). Sets a color using the Red-Green-Blue-Alpha (RGBA) model.

How do you darken colors in Sass?

Using lighten() and darken() in SASS As the names suggest, given a colour and percentage, these functions will return a colour lighter or darker respectively.

How do I darken a hex color in CSS?

The CSS preprocessors Sass and Less can take any color and darken() or lighten() it by a specific value. But no such ability is built into JavaScript. This function takes colors in hex format (i.e. #F06D06, with or without hash) and lightens or darkens them with a value.

How do you use opacity in Sass?

With Sass, just wrap your color with rgba() and the opacity value as you would with normal CSS. Sass will take care of breaking down the color value into the correct RGB values.


1 Answers

Because lighten function is described on HSL colors and your red color #f90 is translated as hsl(0, 100%, 50%)

so lighten($lightred, 50%) is equal to hsl(0, 0, 100%), or white

like image 80
sbagdat Avatar answered Oct 25 '22 17:10

sbagdat