JavaScript的CSS supports方法的语法是什么?

huangapple go评论73阅读模式
英文:

What is the syntax for JavaScript’s CSS supports method?

问题

我正在测试新的:has()伪类。到目前为止,只有Firefox没有默认启用它。

我在https://stackoverflow.com/questions/73936048/how-do-you-enable-has-selector-on-firefox的评论中看到了以下测试:

CSS.supports("selector(:has(:focus))");

当我在Firefox上启用设置时,它返回true,否则返回false,这是预期的结果。

问题是,selector(:has(:focus))实际上是什么意思?显然,它正在测试:has()伪类,但selector()(:focus)部分是什么意思。如果我试图简化它,测试不起作用——至少返回false

我找不到关于CSS.supports()方法的详细文档来讨论这个问题。

英文:

I am testing out the new :has() pseudo class. So far, only Firefox hasn’t enabled it by default.

I read in a comment on https://stackoverflow.com/questions/73936048/how-do-you-enable-has-selector-on-firefox about the following test:

CSS.supports("selector(:has(:focus))"));

It returns true when I’ve enabled the setting on Firefox, and false otherwise, which is expected.

The thing is what does the selector(:has(:focus)) actually mean? Obviously it’s testing for the :has() pseudoclass, but what’s with the selector() and the (:focus) parts. If I try to simplify it, the test doesn’t work — at least it returns a false.

I can’t find any detailed document on the CSS.supports() method which discusses it.

答案1

得分: 2

OK,我明白了。

  • selector() 测试语法 :has(:focus) 是否可接受。
  • has(:focus) 是一个虚拟测试。:has() 不会起作用,因为它不能有一个空值,所以必须是 :has( something )。评论者使用了 :has(:focus),但也可以使用 :has(p):has(gorilla):has(…)

所以,用英语来说,这个测试是检查CSS是否支持语法 :has(anything)

英文:

OK, I think I understand.

  • selector() tests whether the syntax :has(:focus) is acceptable.
  • has(:focus) is a dummy test. :has() won’t work because you can’t have an empty value, so it has to be :has( something ). The commenter use :has(:focus) but could just as well have used :has(p) or :has(gorilla) or :has(…).

So, in English, the test is whether CSS supports the syntax :has(anything).

huangapple
  • 本文由 发表于 2023年7月20日 13:46:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76726987.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定