2016-06-21 27 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僞類表示一個元素,該元素是其父類元素的子元素列表中其類型的最後一個元素的最後一個元素。