News for hackers. Stuff that matters.
Re:Uses for CSS Custom Properties by codyb on Wednesday December 18, 2019 @01:14PM (#21827568)
Wow, that’s really neat, I never thought of using css variables in this manner. Although, to be fair, I never knew they were called custom properties either.

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.

Re:Uses for CSS Custom Properties by cyptus on Wednesday December 18, 2019 @09:41AM (#21825264)
usign css attr() for getting html data- attributes is also very interesting.

i use this for simple e-mail spam protection: https://stackoverflow.com/a/41566570/1216595

Re:Uses for CSS Custom Properties by wolfgang42 on Wednesday December 18, 2019 @12:44PM (#21827288)
As others have noted, this is a neat-looking solution but breaks a lot of things. In addition to copy/paste:

* 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.
Re:Uses for CSS Custom Properties by cyptus on Thursday December 19, 2019 @01:13AM (#21832414)
sure this breaks the copy and right-click implementation, but most of the users dont need it and will just do a normal click to get in touch. If this is the pain i need to go to receive zero spam mails from page-crawlers, i go for it. Advantage to img-solution is full use of css fonts and text aligns. Also any js-solution which would render the plain email into the DOM will receive spam, as crawlers do already execute js before parsing (also think of SPA).
Re:Uses for CSS Custom Properties by GrumpyNl on Wednesday December 18, 2019 @11:16AM (#21826337)
You can not copy the email address, it will be copied backwards. Then you might as well show a image with the address because you already lost the ability to copy and paste.
Re:Uses for CSS Custom Properties by true_religion on Wednesday December 18, 2019 @12:05PM (#21826883)
You can intercept copy and paste using JavaScript.
Re:Uses for CSS Custom Properties by egfx on Wednesday December 18, 2019 @01:53PM (#21827966)
This is cool. You can also tool around with https://gif.com.ai to bring out creative use cases of such properties.
Re:Uses for CSS Custom Properties by aldoushuxley001 on Wednesday December 18, 2019 @01:43PM (#21827875)
Wish they had a section that detailed the browser support for them as well, as that seems to be the major drawback.
Re:Uses for CSS Custom Properties by leepowers on Wednesday December 18, 2019 @01:58PM (#21828018)
Re:Uses for CSS Custom Properties by egfx on Wednesday December 18, 2019 @04:32PM (#21829694)
>93% support doesn’t seem much of a drawback.
Re:Uses for CSS Custom Properties by dbbk on Thursday December 19, 2019 @05:57AM (#21833765)
It's only IE 11 that doesn't support it, you can probably drop that now depending on your customer base.
Re:Uses for CSS Custom Properties by ape4 on Wednesday December 18, 2019 @09:19AM (#21825057)
--l looked like C++ pre-decrement on first read.
Re:Uses for CSS Custom Properties by pintxo on Wednesday December 18, 2019 @09:43AM (#21825287)
Anyone knows the reasoning for using `--` as the prefix for variables?
Re:Uses for CSS Custom Properties by gorbert on Wednesday December 18, 2019 @12:29PM (#21827150)
They talk about reasons for choosing `--` here: https://www.xanthir.com/blog/b4KT0

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.

Re:Uses for CSS Custom Properties by philo23 on Wednesday December 18, 2019 @10:20AM (#21825696)
Presumably they can't just use one dash to avoid clashes with vendor prefixes (-moz-, -webkit- etc.)

I don't think I've ever actually checked, but I always assumed valid CSS property names can only be alpha-dash strings.

Re:Uses for CSS Custom Properties by have_faith on Wednesday December 18, 2019 @11:55AM (#21826789)
> 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.