CSS2提供对生成内容的控制,这将允许您使用:before伪类独立于项目的其余部分设置自动生成的内容的样式.这是符合OP的后续标准的解决方案(列表枚举器的背景颜色,但不符合项目).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
body { margin: 0; padding: 10px; }
ol {
counter-reset: item;
margin: 0;
padding: 0;
}
li {
display: block;
padding: 10px 0;
margin: 0 0 10px 0;
}
li:before {
content: counter(item);
/*
To generate punctuation after the number, just precede or follow with a string:
content: "Chapter " counter(item) " >> ";
To make nested counters (1, 1.1, 1.1.1, etc.), use:
content: counters(item, ".");
*/
counter-increment: item;
background-color: #ddd;
margin-right: 15px;
padding: 10px;
}
ol li ol { margin-bottom: -10px; padding-top: 10px; }
ol li ol li { margin: 10px 0 0 30px; }
</style>
</head>
<body>
<ol>
<li>Turtles</li>
<li>Lizards
<ol>
<li>Salamanders</li>
<li>Geckos</li>
</ol>
</li>
<li>Velociraptors</li>
</ol>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1444 次 |
| 最近记录: |