因为li:nth-child(1)指的是作为第一个子元素的li,加入span之后,span就变成了ul的第一个子元素,所以li:nth-child(1)会失效,因为li已经不是太子了;建议使用first-of-type,nth-of-type,last-of-type第一个子孩子的hover,你根本就没写。第三个的hover,你写成 border:1px red solid; 试试
失效原因:使用:first-child伪类时一定要保证前面没有兄弟节点,把h1去掉就可以;或者使用div包住article,然后css:div.article:first-child或者使用first-of-type 1 2 3 article:first-of-type{ color: red; } :first-child 匹配的是某父元素的第一个子元素,可以说是结构上的第一个子元素。 :first-of-type 匹...
因为li:nth-child(1)指的是作为第一个子元素的li,加入span之后,span就变成了ul的第一个子元素,所以li:nth-child(1)会失效,因为li已经不是太子了;建议使用first-of-type,nth-of-type,last-of-type