2017-03-08 21 views
0

我有一個具有list-style-type屬性的特定值的有序列表,我希望它不會影響其子級。僅在父級上應用列表樣式類型,而不是子級

當前,有序列表中嵌套了另一個有序列表,它繼承了list-style-type值。我該如何禁用?

<ol class='custom-ol'> 
    <li> cat1: 
    <ol style="list-style-type:lower-alpha"> 
    <li>text 1</li> 
    <li>text2</li> 
    </ol> 
    </li> 
    <li> 
    cat2: 
    <ol style="list-style-type:lower-alpha"> 
    <li>text 3</li> 
    <li>text 4</li> 
    </ol> 
    </li> 

css樣式

<style> 
    .custom-ol ol 
    { 
     counter-reset: custom-counter; 
     list-style-type: none; 
    } 
    .custom-ol ol li 
    { 
      counter-increment: custom-counter; 
    } 

    .custom-ol ol li:before 
    { 
      content:"(" counter(custom-counter) ") "; 
      font-weight:bold; 
    } 

</style> 

我試圖修復,以這種方式,但它不是在所有工作(更新版)

這就是我得到

ol.custom-ol 
{ 
    counter-reset: custom-counter; 
    list-style-type: none; 
} 
ol.custom-ol li 
{ 
     counter-increment: custom-counter; 
} 

ol.custom-ol li:before 
{ 
     content:"(" counter(custom-counter) ") "; 
     font-weight:bold; 
} 

ol ol { 
    list-style-type: lower-alpha; 
} 

enter image description here

我想父母(現在是1將是(1)與。定製醇類 和他的孩子是因爲它們是A,B,C不適用(1),(2)

回答

0

這是你的CSS應該是什麼樣子:

ol.custom-ol 
{ 
    counter-reset: custom-counter; 
    list-style-type: none; 
} 
ol.custom-ol li 
{ 
     counter-increment: custom-counter; 
} 

ol.custom-ol li:before 
{ 
     content:"(" counter(custom-counter) ") "; 
     font-weight:bold; 
} 

ol ol { 
    list-style-type: lower-alpha; 
} 

ol ol li:before { 
    content: ""; 
} 
+0

css中的選擇器? –

+0

@AdirZoari是的,那一個 – Larpee

+0

@AdirZoari讓我知道它是否有效 – Larpee

0

你根本沒有針對你的父母ol,你將目標定位爲子女ol兩次。一旦通過內聯樣式:

style="list-style-type:lower-alpha"

,一旦通過你的CSS文件:

.custom-ol ol 
    { 
     counter-reset: custom-counter; 
     list-style-type: none; 
    } 

如果您希望禁用的子元素list-style-type: none,然後更改.custom-ol ol.custom-ol。這將僅針對您的父母ol

或者,嘗試添加!importantstyle="list-style-type:lower-alpha"這樣的:

style="list-style-type: lower-alpha !important"

這將覆蓋應用到子ol任何其他樣式。

+0

我試圖讓!重要的和這種風格相同的問題。 –

+0

你可以更具體地說明你想要應用的風格和什麼元素? –

+0

是的,看看編輯帖子,我發表了照片 –

相關問題