2

我有一个罕见的需求:

只有当我有<ol>孩子并且没有更多标签时,我才需要样式“list-style:none”。

例如,在这种情况下,我将应用样式:

<div>
  <ol><li>1</li></ol>
  <ol><li>2</li></ol>
</div>

在彼此中,我将禁用该样式:

 <div>
  <p>
  <ol><li>1</li></ol>
</div>

什么是最好的方法?谢谢

4

3 回答 3

1

This is not possible with pure CSS. You'll have to either modify the HTML to add classes manually, or use a script to determine if there are only ol elements inside and no other types of children, then apply the class or the style.

于 2012-08-17T10:51:21.567 回答
0

试试这个。

div ol:only-of-type {
    list-style: none;
}

任何只有一个 li 元素的列表现在都应该没有列表样式。

仅与 IE9+ 兼容(以及所有其他)

来源: http: //net.tutsplus.com/tutorials/html-css-techniques/the-30-css-selectors-you-must-memorize/

演示:http: //jsfiddle.net/RGnJW/

于 2012-08-17T10:16:43.567 回答
-1

您可以使用以下 CSS:

ol li {
    list-style: none;
}
于 2012-08-17T10:19:49.910 回答