简体   繁体   English

CSS 属性值中的波浪号

[英]Tilde in CSS attribute value

I found some CSS like this:我发现了一些这样的 CSS:

margin-top: ~"-2px\9";

Can anyone tell me what it is and what it does?谁能告诉我它是什么以及它有什么作用?

What is it?它是什么?

A syntax error.语法错误。

What does it do?它有什么作用?

Breaks your stylesheet.破坏您的样式表。


As mentioned in the comments on your question, it may be LESS instead of CSS.正如对您的问题的评论中所述,它可能是 LESS 而不是 CSS。 In LESS, a tilde before a string literal outputs the string as-is, because it may be a syntax error in pure LESS.在 LESS 中,字符串文字前的波浪号按原样输出字符串,因为它可能是纯 LESS 中的语法错误。 \\9 is an IE hack . \\9一个 IE 黑客 See Escaping .转义

It may be a LESS Syntax.它可能是一个 LESS 语法。 But tilde character is used in CSS3 as well.但是代字号也在 CSS3 中使用。 Eg the below Syntax:例如下面的语法:

p ~ ul { background:#ff0; }

will target ul elements that are preceded by ap element with the same parent:将定位在具有相同父元素的 ap 元素之前的 ul 元素:

In Less, this is called "Escaping" .在 Less 中,这称为“转义”

Escaping allows you to use any random string as a property value or variable value.转义允许您使用任何随机字符串作为属性值或变量值。

For example ~"value" or ~'value' will be used as is without changes being made, only exception is interpolation.例如~"value"~'value'将按原样使用而不进行更改,唯一的例外是插值。

Link to Less Docs: http://lesscss.org/#escaping链接到更少的文档: http : //lesscss.org/#escaping

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM