2017-02-13 78 views
0

之前與加里我想在做這個列表中的李前添加li如何選擇CSS

ul.ssmenu:first-child::before{ 
    li{ 
     position: relative; 
     height: 10px; 
    } 
} 

這似乎不是正確的解決方案。

回答

1

您不能使用CSS添加像這樣的元素,::before是一個元素,雖然是一個僞元素,並且您可以這樣做...,並且如果您需要更多li,您需要使用腳本

ul li, 
 
ul::before, 
 
ul::after { 
 
    position: relative; 
 
    height: 20px; 
 
} 
 
ul::before { 
 
    content: 'This li were added with CSS pseudo ::before'; 
 
    display: list-item; 
 
} 
 
ul::after { 
 
    content: 'This li were added with CSS pseudo ::after'; 
 
    display: list-item; 
 
}
<ul> 
 
    <li>This "li" exist in markup</li> 
 
</ul>

0

試試這個

ul.ssmenu{ 
    li:first-child::before{ 
     position: relative; 
     height: 10px; 
    } 
}