css选择器
2016-11-26 23:50:32 0 举报
AI智能生成
css选择器学习笔记
作者其他创作
大纲/内容
选择文档中的元素以应用样式
利用元素属性选择
类选择器
多类选择器
html标签中class属性可能为一个词列表,词之间用空格分隔,词的顺序不会影响样式。
.class1.class2{color:red}
单类选择器
id选择器
属性选择器
简单属性选择器
选择有某个属性的元素,而不论该属性的值是什么
h1[class]{color:slive;}
具体属性选择器
只选择有特定属性值的元素
a[href="http://www.baidu.com"]{color: slive;}
部分属性选择器
选择属性中包含某个值的元素
p[class~="warning"]{color:red;}
子串匹配属性选择器
[foo^="bar"]
选择foo属性值以“bar”开头的所有元素
[foo$="bar"]
选择foo属性值以“bar”结尾的所有元素
[foo*="bar"]
选择foo属性值中包含子串“bar”的所有元素
特定属性选择器
[att|="val"]
属性等于val或以val开头的所有元素
利用文档结构选择
后代选择器
h1 em{color: gray;}
子元素选择器
h1>strong{color: gray}
相邻兄弟元素选择器
h1+p{color: gray;}
伪元素选择器
:first-letter
:first-line
:before
:after
利用元素状态选择
伪类选择器
静态伪类
:link
:visited
动态伪类
:focus
:hover
:active
0 条评论
下一页