Umair A.
Umair A.

Reputation: 6873

CSS content property

I want to write \ slash as value in content property of CSS class but it is breaking single quotes so I am using \\ (double slashes).

a:before {
    content: '\\';
}

Am I doing it right?

Upvotes: 1

Views: 222

Answers (2)

Josh Crozier
Josh Crozier

Reputation: 240938

Yea, you are doing it right. It works - example here

\ is meant to escape things such as unicode symbols and HTML entities. By putting a \ in as content, it is essentially being ignored, thus you are required to put 2 in order for one to be rendered.

For instance, content: "\2193"; renders a down arrow . Without the escape, you would otherwise just be rendering 2193. Example here

Alternatively, you could add the \ via 5C which is an HTML entity for a \.

content:'\5C' would effectivly render a backslash. Example here

Upvotes: 2

mayabelle
mayabelle

Reputation: 10014

Yes, that is correct. See here: http://www.merttol.com/articles/code/introduction-to-css-escape-sequences.html

Upvotes: 1

Related Questions