How to choose identifiers containing special characters?

I am working with a part of HTML that I cannot change. One of the identifiers in the document:

<div id="a>span.tex"> ... </div>

This is perfectly valid HTML5 syntax for identifiers , however it is not possible to select this identifier in CSS without problems with >and ..

How can I select this id in CSS?

+4
source share
2 answers

You can avoid special characters with backslashes:

#a\>span\.tex {
  color: red;
}
<div id="a>span.tex"> Some funky ID </div>
Run codeHide result

You can even use backslashes in your ID as long as you avoid them with another backslash:

#a\\span\\tex {
  color: red;
}
<div id="a\span\tex"> Some funky ID </div>
Run codeHide result

In fact, lots of crazy lines are valid identifiers in HTML5

#\Β―\\\_\(\ツ\)\_\/\Β― {
  color: red;
}
<div id="Β―\_(ツ)_/Β―"> Β―\_(ツ)_/Β― - but why would you? </div>
Run codeHide result
+3

:

div[id="a>span.tex"] {
    style here;
}

div id, id

0

Source: https://habr.com/ru/post/1658039/


All Articles