Live data from Hacker News

CSS Custom Functions are coming

bram.us

31–40 of 90 posts

Re: CSS Custom Functions are coming

#32
post #4

Thanks. Looks hideous. @function --light-dark(--light, --dark) { result: var(--light); @media (prefers-color-scheme: dark) { result: var(--dark); } }

Yeah, I couldn't believe it at first. If you're going to add imperative programming to CSS, just do it already. Hacking in conditionals in this way feels like a bad joke.

These are closer to macros than functions, especially without css if(). It's nothing that you can't already do.

Re: CSS Custom Functions are coming

#33
post #4

Thanks. Looks hideous. @function --light-dark(--light, --dark) { result: var(--light); @media (prefers-color-scheme: dark) { result: var(--dark); } }

Looks decent to me, I understand they have to stay within the normal look of CSS. That function, other than nesting, could every well be parsed by a 20-year-old parser.

Re: CSS Custom Functions are coming

#36

Today on "everything that's wrong with modern web and more"

It’s just a new addition and change, doesn’t dictate you must write that way. I still use as a tag (I know, HTML).

It's not about how they write CSS, it's about how everyone else does, and what browsers will need to be able to process.

I don't know how you figured their complaint is somehow compat breakage. From what I know, CSS doesn't really have breaking changes.

Re: CSS Custom Functions are coming

#37
post #2

functions in stylesheets? That's nuts. The web is developing in the wrong way.

These aren't functions in the traditional programming sense. Looking at examples in the spec, they're mostly a way to do conditional logic around which properties to apply when (desperately needed in CSS as the only way to do this now—if at all—is with media queries, funky selectors, or as a last resort, JavaScript).

Just finished work on a new CSS framework and would have loved to have stuff like this. If it lands with baseline support, I'd be able to save a lot of footprint using these.

Re: CSS Custom Functions are coming

#40
It seems like the spec draft itself offers a much better example than the article.

https://drafts.csswg.org/css-mixins-1/

I do think it's strange that using a wrapper like var() wasn't required here. Like func() or such. I'd actually rather that var() hadn't existed to begin with, but it should be consistent, at least.

Post reply on HN