2016-06-21 56 views
0

我在申请:last-of-type:before时遇到问题。CSS:最后一种类型和:之前不工作

我有以下几点:

.stepwizard-row:before { 
    position: absolute; 
    top: 0px; 
    content: " "; 
    width: 1px; 
    height: 100%; 
    background-color: #97D3FD; 
} 
.stepwizard-row:before:last-of-type { 
    position: absolute; 
    top: 0px; 
    content: " "; 
} 

但是,:before:last-of-type似乎没有任何效果。

我在做什么错?

+0

请发表[mcve]。 – j08691

+2

从规范 - *每个选择器只能出现一个**伪元素**,如果存在**,它必须出现在代表选择器主题的简单选择器序列之后。* – Harry

+0

@Harry'::之前'是一个伪元素,但':last-of-type'是一个伪类。可能同时使用 – blonfu

回答

4

你有一个错误的顺序,应该是:

.stepwizard-row:last-of-type:before {} 

CSS3 Selectors - 7. Pseudo-elements

只有一个伪元素可以按选择出现,如果存在的话,必须后出现表示选择器的主题的简单选择器的序列注:本规范的未来版本可能允许每个选择器多个伪元素。

顺便说一句,你可以通过使用.class:last-of-type得到意想不到的行为,它真的应的元素,例如工作.parent > div:last-of-type

6.6.5.9. :last-of-type pseudo-class

:nth-last-of-type(1):last-of-type伪类表示一个元素,该元素是其父类元素的子元素列表中其类型的最后一个元素的最后一个元素。