8

I found some CSS like this:

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

Can anyone tell me what it is and what it does?

Navin Rauniyar
  • 10,127
  • 14
  • 45
  • 68

3 Answers3

34

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. In LESS, a tilde before a string literal outputs the string as-is, because it may be a syntax error in pure LESS. \9 is an IE hack. See Escaping.

Community
  • 1
  • 1
7

It may be a LESS Syntax. But tilde character is used in CSS3 as well. E-g the below Syntax:

p ~ ul { background:#ff0; }

will target ul elements that are preceded by a p element with the same parent:

defau1t
  • 10,593
  • 2
  • 35
  • 47
3

In Less, this is called "Escaping".

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.

Link to Less Docs: http://lesscss.org/#escaping

David Arango
  • 1,830
  • 1
  • 11
  • 7