基本代码
h1 {
color: red;
}
1.含有title属性的h1,title属性只要有就行,可以为空
<style>
h1[title] {
color: red;
}
</style>
// <h1 title>我会被染红</h1>
2.含有title属性并且含有id属性的h1,title属性和id属性只要有就行,可以为空
<style>
h1[title][id] {
color: red;
}
</style>
// <h1 title id>我会被染红</h1>
3.title属性为特定值
<style>
h1[title="hehe"] {
color: red;
}
</style>
// <h1 title="hehe">我会被染红</h1>
4.title属性以特定值开头
<style>
h1[title^="hehe"] {
color: red;
}
</style>
// <h1 title="hehe">我会被染红</h1> 以hehe开头
// <h1 title="ahehe">我不会被染红</h1>
5.title属性以特定值结尾
<style>
h1[title$="hehe"] {
color: red;
}
</style>
// <h1 title="hehe">我会被染红</h1> 以hehe结尾
// <h1 title="heheaaa">我不会被染红</h1>
6.title属性包含特定值
<style>
h1[title*="hehe"] {
color: red;
}
</style>
// <h1 title="hehe">我会被染红</h1> 包含hehe
// <h1 title="heaaa">我不会被染红</h1>
7.title属性包含特定值,但这个值前后不能有其他单词,空格可以,也就是这个词要独立
<style>
h1[title~="hehe"] {
color: red;
}
</style>
// <h1 title="hehe">我会被染红</h1> 单独的hehe
// <h1 title="ddd hehe aaa">我会被染红</h1> hehe前后都是空格
// <h1 title="heheaaa">我不会被染红</h1>
// <h1 title="hehe.com">我不会被染红</h1>
8.title属性以特定值开始,或者是特定值加上"-"连接的
<style>
h1[title|="hehe"] {
color: red;
}
</style>
// <h1 title="hehe">我会被染红</h1> 以hehe开始
// <h1 title="hehe-hehe">我会被染红</h1> hehe开始,后面是-
// <h1 title="hehe.hehe">我不会被染红</h1>