目录
标签选择器
p {
color: blueviolet;
}
id选择器
#p1{
font-size: 10px;
}
类选择器
.c1{
color: blue;
}
通用选择器
使用*
选择所有元素: 但是性能比较差,
* {
color: black;
}
可以选择这种方式选择
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
高级选择器
1 . 后代选择器
.c1 div p{
color: blue;
}
2 . 子选择器
div>p {
color: red;
}
3.交集选择器
p{
color: blue;
}
.c1{
font-size: 20px;
}
.c1,p{
background: blueviolet;
}
4. 属性选择器
input[type='text']{
color: fuchsia;
1 .开头匹配 ^, 匹配for属性 u 开头的
[for^='u'] {
color: red;
}
2.结尾匹配 $ ,匹配for属性 wd 结尾的
[for$='wd']{
color: red;
}
3.随机匹配* ,匹配for属性包含s的
[for*='s']{
color: fuchsia;
}
伪类选择器
(记忆方法 爱恨原则) l(ink) o v(isited) e, h(over) a(ctive) te
/*a标签点击前的样式*/
a:link{
color: red;
}
/*a标签点击后的样式*/
a:visited{
color: fuchsia;
}
/*鼠标停留再标签上的时候*/
a:hover{
color: chartreuse;
}
/*鼠标按住的时候*/
a:active{
color: dimgray;
}
伪元素选择器
/*将p标签的第一个字改变样式*/
p:first-letter{
font-size: 100px;
}
/*在P标签之前加入内容*/
p:before{
content: 'hello,';
color: crimson;
/*在p标签之后加入内容*/
}
p:after{
content: 'world';
color: red;
}