[英]Change color of lists in a CSS stylesheet
所以我為html中的一些有序列表提供了一些代碼,並且我試圖制作一個樣式表,為每個添加的深度添加不同的顏色。
例如:
<ol>
<li>This is red</li>
<ol>
<li>This is blue</li>
</ol>
</ol>
如何使用CSS樣式表執行此操作?
嘗試過這樣的事情:
ol.a {
color:blue;
}
ol.b {
color:red;
}
顯然這沒有用,否則我就不會在這里。
HTML:
<ol class="a">
<li>This is red</li>
<ol class="b">
<li>This is blue</li>
</ol>
</ol>
CSS:
ol.a {
color:red;
}
ol.b {
color:blue;
}
下面是正確的CSS
ol li {
color:blue;
}
ol li ol li {
color:red;
}
簡單答案:
ol {
color:blue;
}
ol ol {
color:red;
}
您可以通過這種方式在您的OL上應用CSS-
ol > ol:nth-child(2) { background-color:red; } ol > ol:nth-child(3) { background-color:blue; } ol > ol:nth-child(4) { background-color:green; }
<ol> <li>This is red</li> <ol> <li>This is blue</li> </ol> <ol> <li>This is blue</li> </ol> <ol> <li>This is blue</li> </ol> </ol>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.