
Responsive Web Design with HTML5 and CSS
By :

One other new feature of the CSS Color Module Level 5 specification that is worth a little exploration is the relative color syntax. This lets you amend a color by kind of deconstructing it. At this point, an example may be more useful. Consider swatch 13 in our example file, which is set with this CSS:
.relative {
--bg: #f90;
background-color: hsl(from var(--bg) h s calc(l + 10%));
}
So, here we have a custom property set to a hex value (#f90
). Then, with our hsl()
color function notation, we use the from
keyword to “pick” where we are generating our relative color from. In this case, it is the hex in the line above, but it could be any color set in any of the notations that CSS allows. Then, we can use the letters of the color type, in this case h
, s
, and l
, to get the component parts of the origin color into our current format and then tweak it. In this instance, I have used the calc()
function to brighten...