我已经设置了一个简单的测试页来说明我遇到的问题.
@H_502_2@简而言之,这可以按预期工作(文本格式为粗体,带下划线的红色):
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- <html>
- <head>
- <style>
- [abc=x1] {
- color: red;
- text-decoration: underline;
- font-weight: bold;
- }
- </style>
- </head>
- <body>
- <div abc=x1>hello</div>
- </body>
- </html>
这不会(文本保持黑色,不应用格式):
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
- <html>
- <head>
- <style>
- [abc=1] {
- color: red;
- text-decoration: underline;
- font-weight: bold;
- }
- </style>
- </head>
- <body>
- <div abc=1>hello</div>
- </body>
- </html>
我在两个例子之间唯一改变的是从x1到1的属性值(在CSS和HTML中).
所以看起来你无法匹配数字属性.
有谁知道为什么这……非常……有用……特征……存在吗?
解决方法
将字符串换行以匹配引号…
- [abc="1"] {
- ...
- }
Attribute values must be CSS identifiers or strings.
当你用引号括起来时,你告诉它匹配string.
当你不引用它时,它正在寻找identifier.
In CSS,identifiers (including element names,classes,and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher,plus the hyphen (-) and the underscore (_); they cannot start with a digit,two hyphens,or a hyphen followed by a digit.