Sam
Sam

Reputation: 111

CSS select a class containing plus sign "+"

How can I select an element by class name containing a plus sign +?

E.g.

.frme_150+1 {background-position: 150px 1px;}

The plus value is changed by using JavaScript, is this possible to use + character in selector name?

Upvotes: 8

Views: 3192

Answers (1)

Hashem Qolami
Hashem Qolami

Reputation: 99464

You'd need to escape the plus sign as it has a special meaning in CSS, by using a leading backslash \ as follows:

.frme_150\+1 {
    background-position: 150px 1px;
}

Working Demo.

Or escape the '+' to '\2b ' or '\00002b' (six hexadecimal digits)

Also, you can achieve this by using CSS Attribute Selector:

[class="frme_150+1"] { background-position:150px 1px; }

Working Demo.

Upvotes: 8

Related Questions