刚学习了属性选择器,基本上涉及初级的选择器就是以下内容了,这边做一下记录。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.demo a{
float: left;
display: block;
height: 50px;
width: 50px;
border-radius: 10px;
background-color:#2700ff;
text-align: center;
color: gainsboro;
text-decoration: none;
margin-right: 5px;
font: bold 20px/50px Arial;
}
</style>
</head>
<body>
<p class="demo">
<a href="http://www.baidu.com" class="links item first" id="first">1</a>
<a href="" class="links item active" target="_blank" title="test">2</a>
<a href="images/123.html" class="links item">3</a>
<a href="images/123.png" class="links item">4</a>
<a href="images/123.jpg"class="links item">5</a>
<a href="abc" class="links item">6</a>
<a href="/a.pdf" class="links item">7</a>
<a href="/abc.pdf" class="links item">8</a>
<a href="abc.doc" class="links item">9</a>
<a href="abcd.doc" class="links item last">10</a>
<a href="abcd.doc" class="links">11</a>
</p>
</body>
</html>
以以上位置为例。
1、表示选中a标签下id属性为first的元素。
a[id="first"]{
background-color: yellow;
}
2、表示选中类为links的元素,需注意:class="*" 为精确比匹配!
a[class="links"]{
background-color: yellowgreen;
}
3、表示模糊匹配,只要class里包含links就够了。
a[class*=links]{
background-color: yellow;
}
4、正则表达式至于属性选择器,表示herf的属性以http为开头的元素。
a[href^=http]{
background-color: yellowgreen;
}
5、正则表达式至于属性选择器,表示href的属性以doc结尾的元素。
a[href$=doc]{
background-color: teal;
}
6、子选择器结合属性选择器。表示p元素下的a标签且herf的属性以http为开头的元素。
p > a[href^=http]{
background-color: wheat;
}