Numbering Nested Ordered Lists in HTML
To number nested ordered lists in HTML, a combination of CSS and JavaScript can be employed. This approach works consistently in modern browsers, including those that do not support advanced CSS properties.
CSS Approach:
ol { list-style-type: none; }
ol:before { content: counter(level1) ". "; counter-increment: level1; }
ol li ol { list-style-type: none; counter-reset: level2; }
ol li ol li:before { content: counter(level1) "." counter(level2) " "; counter-increment: level2; }
jQuery Approach (IE6/7 Support):
$('ol ol').each(function(i, ol) { ol = $(ol); ol.children('li').each(function(i, li) { li = $(li); li.prepend('<span>' + level2 + '</span>'); }); });
ol li span { margin: 0 5px 0 -25px; }
By combining these CSS and JavaScript techniques, you can effectively number nested ordered lists in HTML, ensuring consistent formatting across major browsers.
以上是如何在 HTML 中对嵌套有序列表进行编号?的详细内容。更多信息请关注PHP中文网其他相关文章!