CSS 伪类选择器

207 阅读1分钟

** 在P标签开头添加内容**

p::before {content:" 想要添加的内容"}                  ::before  需要结合content使用

** 在P标签结尾添加内容**

p::after{content:"想要在结尾添加的内容"}             一样也要配合content使用

否定选择器

语法         :not(需要被否定的选择器)

p:not(.p3) {
        color:red;
}

所有p标签除了类名为p3的  字体颜色都为红色

用伪类选择多个标签中第几个修饰

语法     :nth-of-type ( n) {想要修改的样式}     其中n可自己选择数字

p:nth-of-type(2){
color:red;
}

选择第一个

语法    :first-of-type {想要修改的样式}

p:first-of-type {
color:red;
} 

选择最后一个

语法 :last-of-type {想要修改的样式}

p:last-of-type {
color:red;
}