Monday , February 3 2025

How to make CSS fractional list for ul li

To display the content of the article, it is not enough to display standard nested lists, because the view will be like this:

1
  1
  2
  3
  4
2
  1
  2
  3
  4
3
  1
  2
  3
  4

I need this view to be like this (the nested sub-items are 1.1, 1.2, 1.3, etc.):

1
  1.1
  1.2
  1.3
  1.4
2
  2.1
  2.2
  2.3
  2.4
3
  3.1
  3.2
  3.3
  3.4

To do this, I placed this block in a div with the class webinpnewlist, and added these styles:

.webinpnewlist ol {
  list-style-type: none;
  counter-reset: item;
  margin: 0;
  padding: 0;
}
.webinpnewlist ol > li {
  display: table;
  counter-increment: item;
  margin-bottom: 0.6em;
}
.webinpnewlist ol > li:before {
  content: counters(item, ".") ". ";
  display: table-cell;
  padding-right: 0.6em;    
}
.webinpnewlist li ol > li {
  margin: 0;
}
.webinpnewlist li ol > li:before {
  content: counters(item, ".") " ";
}

About iryna

I'm Iryna, a web developer from Ukraine with a decade of experience solving complex technical challenges in the world of freelance. Throughout my career, I've worked on everything from troubleshooting server-side issues and optimizing website performance to enhancing user interfaces. On this blog, I share detailed solutions to the technical problems I’ve encountered and methods that have worked best for me. In addition to my technical expertise, I’m also passionate about digital drawing. I hope the tutorials and insights I provide here will help both fellow developers and creatives alike in their own projects.

Check Also

Css styles for WordPress admin in functions.php

If you need to add individual styles, and they are only a couple of lines, …

Leave a Reply

Your email address will not be published. Required fields are marked *