I need help on how to code an ordered list with the power of CSS. In this case, it’s a list with cycles (like number 1 inside a cycle), and a verticle line connecting each list item as shown in the image shown below.
As you’ll see from the code I have tried, the results give an ol list without the cycles but it does not number the list correctly inside the circle and partly the output is not precise.
Here’s the code I used:
Or based on what I could see in your screenshot, I’d argue that you’re not really dealing with a list at all. You could use the same basic approach Archibald did using the css counter but with elements which make more sense to the content.
Thank you for your response. However, I’m using a WordPress theme and I wanted to paste the code you wrote to see how it works, the custom or “Additional CSS” section didn’t accept to save the changes.
it returns the error “Markup is not allowed in CSS.” I think there’s somewhere you can alter to rectify the problem again and I will appreciate it.
However, I have tried my best and I only experienced one issue - adding the verticle line to the list which connects ol li to another. Also, I would appreciate it if the verticle line ends when it touches the last ol li item without extending the line further below the list.
Here’s the code I have tried and it’s giving the results I wanted except the issue mentioned above:
In my CodePen change: padding: 10px 0;
to: padding-top: 10px;
Your screenshot in Post #1 shows the green line extending above the first circle. If you do not want that, instead of editing: padding: 10px 0;
just delete it.
I have never used WordPress so do not know how to add custom code.
Without wishing to muddy the waters as you have two very good answers already I have used most of your css in the following codepen to create a demo.
The position of the numbers is at the vertical centre of the contents height but could be changed as required (with a corresponding change to the line start and finishes). This could have been catered for more easily with css variables for consistency but I didn’t want to change your css too much.
Of course I have had to guess at the html structure you have but the mechanics of the example should work for you. If you want a full answer then we’d need to see the html that you want us to work with.
Here is another version that is just one ordered list in case that was your mark up.
I wanted to take a moment to express my sincere gratitude for your assistance with the CSS code problem. However, there’s an issue where the code works only for a single <ol><li> item in a post. When there is another <ol><li> at the bottom of the same post, it doesn’t reset to list the items from one; instead, it continues numbering from the previous list.
Here’s an output example from the code you wrote above.
I believe this can be corrected with a small adjustment in the code. I’m not entirely sure where the change needs to be made, but I’m confident it can be resolved.
Hello! My sincere gratitude for providing the ultimate solution to the code problem I was facing. Your expertise and assistance have been invaluable, and the solution you provided works perfectly.
Thank you so much for your help. I truly appreciate it!