Hi guys,
First time poster here, so please be gentle. I am hoping one of you CSS gurus can help me out.
I have been struggling with creating a nested ordered list, numbered correctly with decimals, using CSS 2.1 counters. To appear like so:
[B]1. First Sentence
2. Second Sentence
2.1 Sub Sentence
2.2 Sub Sentence
- Third Sentence[/B]
Without a class I have been coding it up like so ,which works fine, but will obviously apply to all OLs across my site:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
ol{
counter-reset: listing ;
}
li {
display: block ;
}
li:before {
content: counters(listing, ".") " ";
counter-increment: listing ;
}
</style>
</head>
<body>
<ol>
<li>First Sentence</li>
<li>Second Sentence</span>
<ol>
<li>Sub-Sentence</li>
<li>Sub-Sentence</li>
</ol>
</li>
<li>Third Sentence</li>
</ol>
</body>
</html>
When I apply a class to my code, it suddenly becomes like so:
[B]1. First Sentence
2. Second Sentence
3. Sub Sentence
4. Sub Sentence
- Third Sentence[/B]
I have found it a struggle to get got my head around the concept of the counters, and then I finally got it right in my mind, before assigning it a class, but as soon as I go to give it a class, it breaks!
Quite simply, according to my code below, I am trying to get the ordered list classed as ‘listing’ to number correctly with counters, without affecting all of the other ordered lists on my website.
My code at the moment is as below:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sample Page - Ordered List</title>
<style type="text/css">
ol.listing {
counter-reset: list;
}
ol.listing li {
display: block;
}
ol.listing li:before {
counter-increment: list;
content: counters(list, ".") " ";
}
</style>
</head>
<body>
<ol class="listing">
<li>First Sentence</li>
<li>Second Sentence</span>
<ol>
<li>Sub-Sentence</li>
<li>Sub-Sentence</li>
</ol>
</li>
<li>Third Sentence</li>
</ol>
</body>
</html>
I am not sure if this is explained too well, but I hope someone knows what I mean. Any ideas where I am going wrong?
P.S. Browser quirks not important (i.e. I know this will not work on pre-IE7 etc)