- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
随着 css var 的引入,我想知道 为什么 --
会被选为表示 var 的原因。
考虑到 CSS 具有半功能 calc
功能,我觉得 --
很容易与其他语言中的减量运算符混淆。
我很好奇是否有任何历史意义或技术限制导致选择 --
。当 CSS 标记通常是单个标记(#、.、@ 等)时,double 尤其让我感到困惑。此外,使用已被其他事物使用的符号也很有趣(尤其是当它对以 --
开头的类名有效时)。
示例:
@custom-media --lt-sm (width < 576px);
--grey300: #e0e0e0;
.navbarItem {
display: inline-block;
text-align: center;
border-top: 1px solid var(--grey300);
border-left: 1px solid var(--grey300);
@media (--lt-sm) {
flex-grow: 1;
}
&:last-child {
border-right: 1px solid var(--grey300);
}
}
免责声明
有些人可能会争论这个问题的有效性,但了解原因是记住特定概念的关键技巧。
我能找到的唯一相关讨论:
In the telcon today, we resolved to use a "--" prefix to indicate custom properties and other custom things.
We discussed whether the prefix is maintained or dropped when referring to the custom property from a var() function, but didn't actually resolve. Discussion in the call leaned toward dropping the prefix, like I do currently with var-* properties, but some side discussion with Simon and Sylvain argued for using the full name, as there are confusing cases like "--0" or "----".
So, while I understand the potential confusion caused by authors possibly thinking that var() can take any property name as an argument, I think it's overruled by the confusion over what needs to be escaped in various circumstances. Escaping rules are always very confusing to authors, so I'm going to go with "use the custom property name literally as the var() argument".
引用:
http://lists.w3.org/Archives/Public/www-style/2014Mar/0467.html
最佳答案
除了避免与其他答案中提到的以单个破折号开头的供应商前缀发生冲突外,请记住,CSS 标识的语法不允许除字母、数字、破折号和下划线以外的任何内容(请参阅section 4.1.3 的 CSS2)。如果自定义属性由任何其他符号表示,每个现有的 CSS 实现都需要更新甚至重写其解析器,以适应用于自定义属性名称的任何符号。1
来自minutes通过消息中提到的电话,您可以看到避免与以单个破折号开头的供应商前缀发生冲突的假设是正确的。 --
的使用确实需要对解析器进行较小的更改,因为 idents normally cannot start with double dashes (正如 klumme 指出的那样)。我不确定现有的实现是如何解析 (d) 声明的,但是可以安全地假设我的推理仍然成立:因为 idents 可以 以一个破折号开头,所以使用第一个破折号不会立即导致解析错误,因此解析器可以确定它是否正在查看 <property>
或 <custom-property-name>
(或者 然后 如果它不支持自定义 Prop 会遇到解析错误),然后再决定应该如何进行。
此更改也反射(reflect)在 css 变量规范中,在 section 2 中(我也介绍了 here ):
A custom property is any property whose name starts with two dashes (U+002D HYPHEN-MINUS), like
--foo
. The<custom-property-name>
production corresponds to this: it’s defined as any valid identifier that starts with two dashes.
所以使用破折号是因为它们适合现有的语法,只需要对解析器进行微小的更改,并且特别加倍以防止与供应商前缀冲突(请注意,破折号和下划线对于供应商前缀是可以互换的,因此单个下划线不会削减它要么)。
1 事实上,我给了this very same reasoning就在几周前回答别人的问题时,尽管他们的问题不是关于为自定义 Prop 名称选择的前缀。
关于css - CSS 中是否有任何技术限制导致决定将 `--` 用于 vars?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42622197/
这个问题已经有答案了: Can I bind an array to an IN() condition in a PDO query? (23 个回答) 已关闭 5 年前。 任何人都可以看到我如何在
我阅读了关于此的 bash 手册页,但我不明白其中的区别。我对它们进行了测试,它们似乎产生了完全相同的结果。 如果值不是通过命令行参数设置的,我想设置一个变量的默认值。 #!/bin/bash var
我为我的网站开了一家商店,并让它运行起来,但我意识到它无法正确购买商品。换句话说,您不会走进一家商店,拿起一件商品,购买,再次购买,购买,再次购买,等等,以获得想要的数量。你一次捕获他们。我的网站缺少
基本上,我想知道为什么会这样(将列表的内存地址作为参数传递): void init_lista (elemPtr *list) { *list = NULL; } int main(){
看到这个问题:Is there a (built-in) way in JavaScript to check if a string is a valid number?还有这个:jsperf ,其
我有以下字符串: 我想用正则表达式替换所有后面有 px 的数字,并用 X 乘以它们的值。 (X 是一个变量)。 所以如果X=3,结果就是 请注意 X 必须是我将检索到函数的变量 最佳答案 以下代码
这个问题在这里已经有了答案: 关闭 13 年前。 同时 (var != var) System.out.println("循环.."); 执行它..如何声明..var
我只是好奇。我想知道表达式是否有特定原因 var &= expr 行为方式与不同 var = var && expr. 看起来第一个表达式中的表达式正在执行,而不管 var 上的 false 值。 我
我有这个 Ruby 代码: var1 = 10 puts var1.object_id var1 = var1 + 0 puts var1.object_id var1 = var1 + 1 puts
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: demote boost::function to a plain function pointer 所以我
好吧,堆栈溢出, 我花了几个小时来解决 javascript 中的问题(在 NodeJS 服务器中编写),但我真的不明白。 这就是发生的事情: var data = {x: 50}; var temp
首先,我在这里处理 1 和 0,我很清楚 1 == true 和 0 == false。但是我很好奇为什么这不起作用: $var = 1; echo $var; /* 1 */ $var = $var
标题说的是什么:将变量封装在 {}、"" 或 "{}"中是什么意思?我无法在网上找到关于此的任何解释 - 除了使用不会产生任何结果的符号外,我无法引用它们。 这是一个例子: declare -a gr
我需要将信息发送到我的 Html。例如 $(document).ready(function() { var = "'#"+result.tag+"'" // var = '#tag_dinamy
是否可能,如果可以,如何将以下表达式转换为一行? DEV=$(lsblk -no KNAME,MODEL | grep 'ModelNAME') DEV=${DEV%%'ModelNAME'} 简单的
isset($var) == "Test" 和 isset($var) && $var == 'Test" 有什么区别? 最佳答案 这里是一个简短的例子: $var = "Chuck Test"; v
isset($var) == "Test" 和 isset($var) && $var == 'Test" 有什么区别? 最佳答案 这里是一个简短的例子: $var = "Chuck Test"; v
如果我有一个字符串:[Object a:var b:var c:var]; 如何将 a:、b: 和 c: 与正则表达式匹配? 我试过:\[.+\s+(.+:).+\] 但它不适用于 a、b 和 c,它
这个问题在这里已经有了答案: Why does this if-statement combining assignment and an equality check return true? (
我正在 Powershell 中使用 SCSM,但遇到了 if 语句的问题。 我有一个函数,它根据作为变量传递给函数的条件收集数据。 例子: $JMLs1 = collectTickets -crit
我是一名优秀的程序员,十分优秀!