473,513 Members | 2,684 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Automated numbering of nested lists with CSS

2 New Member
Hello! This is actually a reply to post:
http://www.thescripts.com/forum/threadnav100612-1-10.html
from July 2005, to which I can't reply.
The following code does "Automated numbering of nested lists with CSS". It is standard CSS, and works with Firefox and Opera. If anyone can test it with other browsers, I'd be grateful. I won't be surprised if it doesn't work with some versions of Internet Explorer, which doesn't do a great work with CSS:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <style type="text/css">
  4. ul.numerada{
  5.  counter-reset:c1;
  6. }
  7.  
  8. ul.numerada > ul > ul {
  9.  counter-reset:c2;
  10. }
  11. ul.numerada > ul > ul > ul {
  12.  counter-reset:c3;
  13. }
  14. li{                                 
  15.  list-style-type: none;
  16. }
  17. ul.numerada > ul > li:before{
  18.  counter-increment:c1;
  19.  content: counter(c1) " ";
  20.  background-color:gray;
  21. }
  22. ul.numerada > ul > ul > li:before{
  23.  counter-increment:c2;
  24.  content: counter(c1) "." counter(c2) " ";
  25.  background-color:pink;
  26. }
  27. ul.numerada > ul > ul > ul > li:before{
  28.  counter-increment:c3;
  29.  content: counter(c1) "." counter(c2) "." counter(c3) " ";
  30.  background-color:yellow;
  31. }
  32. </style>
  33. </head>
  34. <body>
  35. <ul class="numerada">
  36.  <li>rar</li>
  37.  <li>rar</li>
  38.  <li>rar</li>
  39. <ul>
  40.  
  41.  <li>rar</li>
  42. <ul>
  43.  <li>rar</li>
  44.  <li>rar</li>
  45.  <li>rar</li>
  46.  
  47. </ul> <li>rar</li>
  48.  <li>rar</li>
  49. <ul>
  50.  <li>rar</li>
  51.  <li>rar</li>
  52. <ul>
  53.  <li>rar</li>
  54.  <li>rar</li>
  55.  <li>rar</li>
  56.  
  57. </ul> <li>rar</li>
  58.  
  59.  
  60.  <li>rar</li>
  61.  <li>rar</li>
  62.  <li>rar</li>
  63.  
  64. </ul>
  65. </ul>
  66.  <ul>
  67.  <li>rar</li>
  68.  <li>rar</li>
  69.  <li>rar</li>
  70.  
  71. </ul>
  72. </ul>
  73. </body>
  74. </html>
  75.  
  76.  
Jan 2 '07 #1
4 2316
morrhamen
2 New Member
Just noticed that the first level is skiped. This is a fix:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <style type="text/css">
  4. .numerada{
  5.  counter-reset:c1;
  6. }
  7.  
  8. .numerada > ul > ul {
  9.  counter-reset:c2;
  10. }
  11. .numerada > ul > ul > ul {
  12.  counter-reset:c3;
  13. }
  14. li{                                 
  15.  list-style-type: none;
  16. }
  17. .numerada > ul > li:before{
  18.  counter-increment:c1;
  19.  content: counter(c1) " ";
  20.  background-color:gray;
  21. }
  22. .numerada > ul > ul > li:before{
  23.  counter-increment:c2;
  24.  content: counter(c1) "." counter(c2) " ";
  25.  background-color:pink;
  26. }
  27. .numerada > ul > ul > ul > li:before{
  28.  counter-increment:c3;
  29.  content: counter(c1) "." counter(c2) "." counter(c3) " ";
  30.  background-color:yellow;
  31. }
  32. </style>
  33. </head>
  34. <body>
  35. <div class="numerada">
  36. <ul>
  37.  <li>rar</li>
  38.  <li>rar</li>
  39.  <li>rar</li>
  40. <ul>
  41.  
  42.  <li>rar</li>
  43. <ul>
  44.  <li>rar</li>
  45.  <li>rar</li>
  46.  <li>rar</li>
  47.  
  48. </ul> 
  49.  <li>rar</li>
  50.  <li>rar</li>
  51. <ul>
  52.  <li>rar</li>
  53.  <li>rar</li>
  54.  <li>rar</li>
  55.  
  56.  
  57.  <li>rar</li>
  58.  <li>rar</li>
  59.  <li>rar</li>
  60.  
  61. </ul>
  62. </ul>
  63. <li>rar</li>
  64.  <ul>
  65.  <li>rar</li>
  66.  <li>rar</li>
  67.  <li>rar</li>
  68.  
  69. </ul>
  70. </ul>
  71. </div>
  72. </body>
  73. </html>
  74.  
  75.  
Pablo Angulo
Jan 2 '07 #2
ronverdonk
4,258 Recognized Expert Specialist
Both solutions do not work on my IE 6.

Ronald :cool:
Jan 7 '07 #3
drhowarddrfine
7,435 Recognized Expert Expert
You have misplaced your <ul> tags or closing </ul> tags. Either your <ul> tags are not matched properly with the closing tags or, if you are trying to make a <ul> one of the list items, then you need to enclose it in <li> tags.

Make sure you are using a proper strict doctype, too.
Jan 8 '07 #4
AricC
1,892 Recognized Expert Top Contributor
When you say automated I think more of a loop in Javascript to achieve this.
Jan 8 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

25
12667
by: chad | last post by:
I am writing a program to do some reliability calculations that require several nested for-loops. However, I believe that as the models become more complex, the number of required for-loops will...
15
2642
by: Xah Lee | last post by:
Here's the belated Java solution. import java.util.List; import java.util.ArrayList; import java.lang.Math; class math { public static List range(double n) { return range(1,n,1); }
0
2940
by: Knepley, Jim | last post by:
I'm basing some work on Joe Celko's excellent idea of using nested sets to represent an organizational structure as opposed to an adjacency list. By and large it's a great idea, but not without its...
6
2835
by: Stanimir Stamenkov | last post by:
So if the 'type' attribute of the OL element is deprecated and authors should rely only on stylesheets how one could use a reference (as clear text) in the content to a particular list element? ...
7
4401
by: Jane Withnolastname | last post by:
I have a number of unordered lists nested within ULs nested within ULs nested within ULs. I have set the style for LI to be .7em. Mozilla gives me the layout as I imagined it, with the lists...
4
7095
by: Lee K. Seitz | last post by:
I'm still relatively new to stylesheets. I'm trying to do something that seemed fairly simple on the surface, but is proving to be a challenge. I have a set of nested lists: <ul> <li>Side...
7
3631
by: patrick j | last post by:
Hi I'm wondering about lists with nested lists as one does on a Saturday afternoon. Anyway below is an example of a list with a nested list which the iCab browser's very useful HTML...
0
3495
by: mutt1170 | last post by:
I have a checkbox list nested inside a gridview. The gridview pulls its data from an objectdatasource and lists countries. The nested checkbox list is databound to another object datasource and...
7
2168
by: Zethex | last post by:
Im a bit new to python. Anyway working on a little project of mine and i have nested lists ie Answer = , ] and so forth.., Anyway the amount of ] do increase over time. Im just wondering...
0
7157
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7379
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5682
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5084
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1591
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.