(1)如果有


  • 1

  • 2

  • 3

  • 4

  • 5


对某一个li赋予特殊样式,如果采用令class值的情况,会非常麻烦,因为可能会出现一次赋予多个li样式的情况

(2)采用伪类,即不写class=”” ,而是采用 ul > li:first-child {} 进行对一个li进行样式
但是会出现问题,如下:


    我是span
  • 1

  • 2

  • 3

  • 4

  • 5


即第一个元素不是li的情况下,则无任何样式,那么此时采用 ul > li: first-type-child {} ,即可解决问题
,要进入到这个元素中,然后进行操作

(3)如果一次对多个li进行操作, 采用 ul > li:nth-child(n) ,表示1到无穷大,如果为2n,则只出现偶数赋予样式情况,以此类推

(4)同时也可采用nth-type-child(n)

(5)not是一种否定的伪类,除掉某种特殊情况如:
ul > li:not(nth-child(3)) {}

(6):only-of-type :

Select elements that are the only ones of their type within of their parent element

Examples

p span:only-of-type selects a span within any p if it is the only span in there.