Pipe Chars in HTML Classes

橙三吉。 提交于 2021-01-27 04:42:31

问题


I couldn't find anything in the W3C docs that said pipe chars, |, aren't allowed, for instance:

<div class="class1|class2">

Don't worry about what I might be using it for. I was just wondering if it's "legal".


回答1:


The relevant rules can be found in w3c syndata tokenization section, though it's pretty difficult to conclude from there if pipe is valid or not, as per a glance, it seems that anything is valid for a selector, i.e.:

selector    : any+;
any         : [ IDENT | NUMBER | PERCENTAGE | DIMENSION | STRING
              | DELIM | URI | HASH | UNICODE-RANGE | INCLUDES
              | DASHMATCH | ':' | FUNCTION S* any* ')' 
              | '(' S* any* ')' | '[' S* any* ']' ] S*;



回答2:


It's legal HTML, since the datatype of class is CDATA. You will have a problem with CSS selectors, because the pipe is not a valid character for a selector.




回答3:


It is a valid character in a class name. In fact, I see a website using pipe ( | ) just for the sake of class separation. Which I think is a good practice for readability.



来源:https://stackoverflow.com/questions/2953758/pipe-chars-in-html-classes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!