举个例子 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <ti…
举个例子
<!DOCTYPE html><html lang="en"> <head> <meta charset="utf-8" /> <title>属性选择器例子</title> <style>/**a标签带有href标签的将被匹配**/a[href] { color:red;}/**a标签href="#"标签的将被匹配**/a[href="#"] { color:red;}/**a标签class="one"标签的将被匹配,多属性包含选择**/a[href~="one"] { color:red;}/**a标签href="#"标签的将被匹配,匹配开头="#"的a标签**/a[href^="#"] { color:red;}/**a标签href="#"标签的将被匹配,匹配结束="#"的a标签**/a[href$="#"] { color:red;}/**a标签href="#"标签的将被匹配,匹配开头="#"的a标签及#-value**/a[href|="#"] { color:red;}/**a标签href="#"标签的将被匹配,全局匹配**/a[href*="#"] { color:red;}</style> </head> <body> <a href="">属性选择器</a> <a href="#">属性选择器</a> <a href="#">属性选择器</a> <a href="#" class="one two">属性选择器</a> <a href="#1">属性选择器</a> <a href="#2">属性选择器</a> <a href="1#">属性选择器</a> <a href="2#">属性选择器</a> <a href="#-a">属性选择器</a> <a href="#-a">属性选择器</a> </body></html>
通常*=与&=用的较多