我想列出rottweiler和doberman,如1.1和1.2,但我不知道该怎么做。我复制了那个css列表模板并进行了一些修改。 这是代码:
#lista2 {
counter-reset: li;
list-style: none;
*list-style: decimal;
font: 15px 'trebuchet MS', 'lucida sans';
padding: 0;
margin-bottom: 4em;
text-shadow: 0 1px 0 rgba(255,255,255,.5);
}
#lista2 ol {
margin: 0 0 0 2em;
counter-reset: section;
list-style-type: none;
}
#lista2 li{
position: relative;
display: block;
padding: .4em .4em .4em 2em;
*padding: .4em;
margin: .5em 0;
background: #ddd;
color: #444;
text-decoration: none;
border-radius: .3em;
transition: all .3s ease-out;
}
#lista2 li:hover{
background: #eee;
}
#lista2 li:hover:before{
transform: rotate(360deg);
}
#lista2 li:before{
content: counter(li);
counter-increment: li;
position: absolute;
left: -1.3em;
top: 50%;
margin-top: -1.3em;
background: #87ceeb;
height: 2em;
width: 2em;
line-height: 2em;
border: .3em solid #fff;
text-align: center;
font-weight: bold;
border-radius: 2em;
transition: all .3s ease-out;
}
#lista2 ol ol li:before{
counter-increment: li;
content: counters(li,".") " ";
}
#lista2 ol {
counter-reset: li;
list-style: none;
}

<ol id="lista2">
<li>Animals
<ol>
<li>Dogs</li>
<ol>
<li>Rottweiler</li>
<li>Doberman</li>
</ol>
<li>Cats</li>
<li>Cacatoos</li>
</ol>
</li>
</ol>
&#13;
答案 0 :(得分:1)
Plunkr Link - https://plnkr.co/edit/dtn5xgoOOoSmVc4B3LrH?p=preview
HTML:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
<style>
OL { counter-reset: item }
LI { display: block }
LI:before { content: counters(item, ".") " "; counter-increment: item }
</style>
</head>
<body>
<ol>
<li>Dogs
<ol>
<li>Rottweiler</li>
<li>Doberman</li>
</ol>
</li>
<li>Cats
</li>
<li>Cacatoos</li>
</ol>
</body>
</html>
CSS:
OL { counter-reset: item }
LI { display: block }
LI:before { content: counters(item, ".") " "; counter-increment: item }