Uses for CSS Custom Properties
css-irl.info
css-irl.info
CSS and HTML are pretty powerful as a duo these days, I’ve been doing some freelance work with no JavaScript lately and you really can knock some pretty sweet features right out of the park from collapsible menus, animations, validations with regex’s (and many predefined types like url and email). Combined with grid, flexbox, and the easily read semantic elements I’d say this is the best vanilla web development has ever been.
i use this for simple e-mail spam protection: https://stackoverflow.com/a/41566570/1216595
* Middle-clicking to open my webmail in a new window
* “Right-click > Copy link address” because my browser doesn't know about my email client
* Possibly screen readers (I don’t know this one for certain)
* Keyboard accessibility: I can tab onto the link, but Enter doesn’t activate it
* Probably some other things I haven’t thought of
Since you’re requiring JavaScript anyway, here's a better solution that doesn't decrease resistance to scrapers¹ and fixes the above problems by turning all of your .cryptedmail tags into proper links that work the way users expect them to.:
document.querySelectorAll('.cryptedmail').forEach(a => {
const email = `${a.dataset.name}@${a.dataset.domain}.${a.dataset.tld}`
a.href = `mailto:${email}`
a.innerText = email
})
¹If they’re running JS, they can also just tell Selenium to intercept navigation and then click every link on the page.TL, DR: There was discussion of using properties that look like `$foo` to define variables, but if they used `$foo` for variables, they would be unable to use it for future "variable-like" things. CSS custom properties behave differently from CSS pre-processor variables and they wanted to make that clear. Additionally, it’s to provide a way for custom properties to be used in any preprocessor.
I don't think I've ever actually checked, but I always assumed valid CSS property names can only be alpha-dash strings.
They are, although they also aren't allowed to start with a number. But like most things on the web you're not supposed to do some browsers will still let you get away with it.