html - 如何调整有序列表中的元素而不影响子列表?

标签 html css list

我想定义一个带有无序子列表的有序列表。您可以从下面的示例中看到我想要实现的目标。它的作用是无序列表也获得编号标签。我怎样才能防止这种情况(对于进一步的子列表[所以在级别 3,4,...] 也是如此)?

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <style type="text/css">
      /* %%% ordered lists, see http://stackoverflow.com/questions/2558358/how-to-add-brackets-a-to-ordered-list-compatible-in-all-browsers# %%% */
      ul {
      list-style-type: square;
      padding: 0em 0em 0em 26px; /* indent from left */
      }

      ul li {
      margin: 0.3em 0em 0em 0em; /* space between elements */
      }

      ol {
      list-style-type: none;
      padding: 0em; /* indent from left */
      }

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

      ol.orderedlist li:before {
      content: counter(mycounter) ") ";
      counter-increment:mycounter;
      }
    </style>
  </head>
  <body>
    <ol class="orderedlist">
      <li>Point 1</li>
      <ul>
    <li>Foo</li>
    <li>Bar</li>
      </ul>
      <li>Point 2</li>
      <ul>
    <li>Foo</li>
    <li>Bar</li>
      </ul>
    </ol>
  </body>
</html>

最佳答案

使用子选择器:

ol.orderedlist > li:before {
content: counter(mycounter) ") ";
counter-increment:mycounter;
}

关于html - 如何调整有序列表中的元素而不影响子列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11195400/

相关文章:

firefox - 文本溢出省略号不适用于 firefox 中 &lt;input type ='file'/> 中的选定文件名。请提出解决方案

java - 如何在 java 中列出一个 tar 文件的所有条目?

python - 用逗号连接单词和 "and"

jquery - 如何使用 jQuery slideToggle 扩展内联列表中的嵌套列表?

javascript - 当我用jquery点击外面时如何使覆盖和部分消失

javascript - 如何使用 JavaScript 修复侧边栏错误

css - Bootstrap 3 面板移动滚动/响应

html - 居中所有div

html - 尝试在页脚中将文本彼此相邻移动

c++ - 将集合的随机元素添加到列表中并将其从原始集合中删除