Post

what were your favorite SASS functions (not mixins)? or just other CSS functions you'd expect to be possible by a vanilla CSS function?

3 reposts28 likes

It’s funny, I never really felt the need to use maps in Sass, but now with hundreds (!) of custom properties floating around in my stylesheets, I could totally use something like that

Sass maps are great, together with getter functions, for providing warnings/throwing errors. Note how you can use the & to render out the selector that causes the issue 😀

I've used them for exactly that for projects with tons of custom properties. I divide out the properties into their own files with their own maps (e.g. _colors.scss, _spaces.scss, _z-index.scss). And then my `:root` looks a little cleaner (to me at least!)

The little things are crucial for me: that I can structure my components so nicely with SASS and can therefore reuse them for different projects. It's nothing big, it's not a great feature, but it's the basis.

Was a fan of the color functions. Being able to adjust lightness or saturation on a color allowed for some cool stuff. Like being able to lighten a color by 10% for a hover, or using a darker shade of a background color for a border.

I had a few fun color ones that were over engineered to hell. 1. color scales based on single color values using the named colors in CSS 2. Created a linear-gradient from a single color value 3. Created nice drop-shadows at different heights/sizes + let pass the bg color as an argument

i meant literally functions, but i totally understand the confusion AAANDD i've asked for this many many times too! through various methods like… let me: - add `const: true` inside `@property {}`? - define custom `env()` vars? - have real scoped private vars, not `--_`? i havent won yet.

The most useful one is rgba(). Unfortunately, it's not possible to pass a HEX color as a property to rgba() in plain CSS. As for SASS, I do not support their approach with breaking compatibility with the previous versions. That's not acceptable.

solutions for older browsers is to do it in SASS instead of the browser indeed, they'll simply ignore what they don't understand

Sass is far from dead and most of what it does great should not be native to CSS 🙂 Most functions in my world are coupled to a mixin for flexible use and both are mostly related to introspection/linting and composition - e.g.

I think I have this one which is does something similar: @function strip-unit($number) { @if type-of($number) == 'number' and not unitless($number) { @return math.div($number, $number * 0 + 1); } @return $number; }

Nice! So interesting that while researching the power of CSS variables for my article I created really similar examples. I had no idea about this repo.

Some kind of incrementing function. Eg I'm the nth element. Imagining that n as a var(--n) or something like that, I could use it in a calc() function. Mainly thinking creative coding there.

Not a function, but sass's ability to be used in concert with css-modules was great for us for years. Unfortunately mixins destroy build speed and it became a problem...but it was great while it lasted.

I expected the vanilla attr() to work with any property, but browsers limit it to the content of pseudoelements. :(

Still ARE. Generating polygon points for a clip-path. Regular, equilateral (not necessarily regular), quasi-regular, random. Generating gradient lists. Generally, pretty much everything that involves looping, which was THE reason why I started using Sass to begin with.