CSS属性选择器

/*
E[att]          匹配所有具有att属性的E元素,不考虑它的值。(注意:E在此处可以省略。
                比如“[cheacked]”。以下同。)   p[title] { color:#f00; }
                
E[att=val]      匹配所有att属性等于“val”的E元素   div[class=”error”] { color:#f00; }
 
E[att~=val]     匹配所有att属性具有多个空格分隔的值、其中一个值等于“val”的E元素
                td[class~=”name”] { color:#f00; }
 
E[attr^=val]    匹配属性值以指定值开头的每个元素                    
                div[class^="test"]{background:#ffff00;}
 
E[attr$=val]    匹配属性值以指定值结尾的每个元素    div[class$="test"]{background:#ffff00;}
 
E[attr*=val]    匹配属性值中包含指定值的每个元素    div[class*="test"]{background:#ffff00;}*/


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>

<style>
[type="text"]{ #属性名+值
border: solid 1px red;
}

[xi]{ #属性名
color: green;
}

[class~="c1"]{ #class属性包含c1
color: yellow;
}

[href$="png"]{ #hred属性名+以png结尾的值
color: pink;
}

</style>
</head>
<body>

<input type="text">
<input type="password">
<div xi="huchangxi">huchangxi div</div>
<p xi="huchangxi">huchangxi p</p>
<div class="c1 c2">huchangxi c12</div>

<div class="img">
<a href="http://www.aaa/1.png">1</a>
<a href="http://www.sss/2.jpg">2</a>
<a href="http://www.ddd/3.png">3</a>
<a href="http://www.fff/4.gif">4</a>
</div>

</body>
</html>

 

posted @ 2022-05-22 20:30  呼长喜  阅读(28)  评论(0编辑  收藏  举报