CSS选择器

一、基础选择器

1、元素选择器

例:h1{color:red}

2、类选择器

例:.text{color:red}

3、ID选择器

例:#code{color:red}

4、通配符选择器(*)

例:*{color:red}

5、并集选择器

例:h1,h2,h3,.text,#code{color:red}

二、层次选择器

1、子级选择器

例:div>em{font-size:18px}

2、后代选择器

例:div  em{

  font-size:18px;

}

3、兄弟选择器

例:div+em{

  font-size:18px;

}

4、通用选择器

div~em{

  font-size:18px;

}

三、伪类选择器

1、动态伪类选择器

link  visited  hover  active

2、结构伪类选择器

(1):first-child

(2):last-child

(3):nth-child(n)

(4):nth-of-type

(5):not(:nth-child(n))

(6):only-child

(7):empty

四、伪元素选择器

1、选中第一行

:firstline

2、选中第一个字

:first-letter

3、在标签前面加内容

::before

4、在标签后面加内容

::after

posted @ 2018-08-18 22:42  smuwgeg  阅读(145)  评论(0编辑  收藏  举报