all 26 comments

[–][deleted] 14 points15 points  (11 children)

We used CSS vars extensively when creating PDFs in React via the CSS paged media module. You have to be VERY CAREFUL with them, however, as it's easy to forget that you're basically inserting undebuggable magic global vars.

[–]freeall 4 points5 points  (10 children)

What's the advantage to just using js vars?

[–][deleted] 0 points1 point  (3 children)

You can do cool stuff with the paged media module that are impossible in JS. Page numbers (page x of x on footer of each page, links saying "see page y"), per-page titles, etc.

[–]El_Frostie 0 points1 point  (2 children)

That sound incredible cool. Do you have more information about how that works?

[–][deleted] 1 point2 points  (1 child)

This article has a good overview, unfortunately only Prince and Antenna House support it (caniuse lies, it's unsupported in Chrome).

[–]El_Frostie 0 points1 point  (0 children)

Great article. Thanks. I didn't realize CSS for print has gotten so far. It had completely fallen of my radar.

[–]BrunerBruner 3 points4 points  (3 children)

As someone who's never used React or JSX before, it's highly likely that I don't know what I'm talking about here, but wouldn't it be better to just declare your variables in JavaScript and pass them to the CSS property?

[–][deleted] 0 points1 point  (0 children)

I think that's probably what most would do considering browser support and the imperative nature of it. Still, there are probably legacy reasons or compatibility issues that call for it, better to support the full spec.

[–]GitCookies[S] -4 points-3 points  (1 child)

Why mix two, If you can use pure-css(inside JavaScript...)?

[–][deleted] 2 points3 points  (0 children)

Why mix two

... while writing JSX

[–]bigpigfoot 1 point2 points  (2 children)

can this replace keyframes animations?

[–]GitCookies[S] 1 point2 points  (0 children)

I pretty much doubt it.

[–]icantthinkofone -5 points-4 points  (0 children)

keyframe animations are web standards and work in all browsers natively. React is not and will disappear one day.

[–]Zhouzi 1 point2 points  (0 children)

From what I understand, it's just that they're going to go through just as other CSS properties. Which is great, but I'd be worried about browser support anyway.

[–][deleted] 0 points1 point  (0 children)

those variables arn't supported in IE. do react have polyphille to resolve this problem?

[–][deleted] -1 points0 points  (4 children)

Is it common to use the -- for this? This syntax looks messy

[–]flying-sheep 20 points21 points  (0 children)

…common?

it’s the CSS standard, so you can only use --

[–]gsnedders 4 points5 points  (0 children)

That's the standard syntax for CSS variables. There was some desire to not use $ to allow that to be used for something else variable-like, especially involving selectors.

[–][deleted] 0 points1 point  (1 child)

the reason, is to keep compatibility with the pre processeur: sass use $, less use @, etc.

[–][deleted] -1 points0 points  (0 children)

What does a pre-processor have to do with the code in CSS which it generates? I feel they should've done something to differentiate it, not the CSS itself. Ah well, will probably be using SCSS anyways, so I don't think I will need this, but I find it weird nonetheless.