Live data from Hacker News

CSS Custom Functions are coming

bram.us

81–90 of 90 posts

Re: CSS Custom Functions are coming

#81
post #65
post #2

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

CSS preprocessors like Sass have had functions for, like, ever.

And that's fine as long as there's a "build/process *.sass" step happening on the server before the resulting HTML+CSS is getting sent to the client (browser).

Re: CSS Custom Functions are coming

#82
post #62
post #27

Oh man, and I thought the current JS status-quo was already full of vulnerabilities and privacy risks. If I had mind-boggling amounts of money, one of the things I would do is start an organization to name and shame and give anti-awards to websites that most abuse javascript and whatever-this-will-be. Or a dang mutual fund: "Like an index fund except we don't support companies with websites that require a ridiculous…

Okay you had your FUD, now for the just desserts: This is actually a feature that is likely to reduce the amount of JS that needs to run on the web. It allows for common component-oriented styling patterns to be employed without bloating CSS bundles or using runtime CSS-in-JS functionality to accomplish it. Source: I work on a web development platform (booo, hisss)

I wish someone would give an example of why we need this. Doesn't @scope handle component-oriented styling ?

Re: CSS Custom Functions are coming

#83
post #4

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

This looks wrong to me - it looks like it should always return ‘light,’ because the ‘if prefers dark then return dark’ conditional is introduced after the default result

Is it more like - result is a variable that can be redefined over and over during the function, and whatever value it is at the end, is what’s returned?

Re: CSS Custom Functions are coming

#85

Earlier quoted context omitted.

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.

I didn’t interpret it as a break in compatibility, more so that simply because a new feature or addition in CSS arises it doesn’t stipulate that you have to adopt it. You can still continue on writing CSS how you want to. I appreciate that it makes it more difficult when new features come about in a language and you have to work on a shared codebase, you sometimes spend a while looking at many differing ways to achieve the same result.

Re: CSS Custom Functions are coming

#86

Earlier quoted context omitted.

coming to all major browsers Chrome, Chrome, Chrome, and Chrome?

Too many on HN seem to forget that Safari exists and has a large market share. If you break Safari then no one on an iPhone or iPad can use your site. That's an unacceptable level of breakage for almost every site, and is enough to ensure that if Apple doesn't implement it it won't be used. Ironically, Apple's walled garden is the last thing standing between Google and total web dominance.

> If you break Safari then no one on an iPhone or iPad can use your site.

A CSS issue is not going to break any site unless it causes interactive elements to overlap or be hidden from view. Most sites do not implement bleeding-edge features for this reason. Those that want to set it up will do it in such a way that there's a fallback for browsers that don't support that function.

Re: CSS Custom Functions are coming

#87
post #11

Was https://en.wikipedia.org/wiki/JavaScript_Style_Sheets right all along?

I didn't know about this and looked it up. I've played around with P5.js, the Canvas-based library for animations and generative art, and this syntax is almost exactly how DOM elements are styled in there.

Re: CSS Custom Functions are coming

#88
post #74

I'm confused at all the negativity? I am personally very excited for this feature, it's going to enable one to use less JavaScript,and CSS to accomplish things that should be easy.

The syntax is getting pretty un-CSS like though, so how much of a benefit is it going to be? FE developers would still have to learn another new way of doing something that can be handled with JS.

Re: CSS Custom Functions are coming

#89
post #62
post #27

Oh man, and I thought the current JS status-quo was already full of vulnerabilities and privacy risks. If I had mind-boggling amounts of money, one of the things I would do is start an organization to name and shame and give anti-awards to websites that most abuse javascript and whatever-this-will-be. Or a dang mutual fund: "Like an index fund except we don't support companies with websites that require a ridiculous…

Okay you had your FUD, now for the just desserts: This is actually a feature that is likely to reduce the amount of JS that needs to run on the web. It allows for common component-oriented styling patterns to be employed without bloating CSS bundles or using runtime CSS-in-JS functionality to accomplish it. Source: I work on a web development platform (booo, hisss)

> This is actually a feature that is likely to reduce the amount of JS that needs to run on the web.

The bulk of JS executed on websites today seem to be for 2 things:

- serving ads and tracking

- running a single-page app framework

Can something like this really derail the React/Vue train?

Re: CSS Custom Functions are coming

#90
post #17

This is it. This is all I’ve wanted in CSS for the last decade. In fact, I just wanted basic mixins without function-like behavior, but this gets me there. The comments here indicate that the article doesn’t do much to explain what this does or why you’d want it, but basically this gives you a way to reuse blocks of styles without needing to resort to e.g. utility classes or other hacks that get around specificity is…

Can these be used as mixins? I looks like there’s only a single return value. Edit: Looks like mixins are planned: https://github.com/w3c/csswg-drafts/issues/9350#issuecomment...

Yes good point, this is unfortunately just the first part of the proposal being implemented. Mixins are the next part.
Post reply on HN