[attribute] 用于选取带有指定属性的元素。 [attribute=value] 用于选取带有指定属性和值的元素。 [attribute~=value] 用于选取属性值中包含指定词汇的元素。 [attribute|=value] 用于选取带有以指定值开头的属性值的元素,该值必须是整个单词。 [attribute^=value] 匹配属性值以指定值开头的每个元素。 [attribute$=value] 匹配属性值以指定值结尾的每个元素。 [attribute*=value] 匹配属性值中包含指定值的每个元素。
下面的例子为包含指定值的 title 属性的所有元素设置样式。适用于由空格分隔的属性值:[title~=hello] { color:red; }下面的例子为带有包含指定值的 lang 属性的所有元素设置样式。适用于由连字符分隔的属性值:[lang|=en] { color:red; }
~= where value must be one Independent words, such as [title~=test], test a can be selected, testa cannot be selected.
*=The value only needs to be a substring of the value. For example, test-a, test a and testa can all be selected.
|= has the same characteristics as ~=, ^= has the same characteristics as *=. Therefore, it is usually better to use ^= and *=.