Having trouble with the numbering system - any suggestions on how to resolve this issue?

I am experiencing an issue with numbering a list

.content ol {    
    padding-left: 0px;
    counter-reset: item;
}

.content ol > li {
    display: block;
}

.content ol > li::before { 
  content: counters(item,  ". ") " " ; 
  counter-increment: item;
}

.content ol ol > li {
    display: block;
}

.content ol ol > li::before {    
  content: counters(item,  ". ") ". " ; 
}

This is the HTML code I am using:

<div id="test">
  <ol>
    <li> item1</li>
    <li> item2

    <ol>
      <li>item 2.1</li>
      <li>item 2.2
      <ol>
        <li>item a</li>
        <li>item b</li>
        <li>item c </li>
      </ol>
    </li>
    <li>item 2.3</li>
    </ol>
    <li>item 3</li>
  <ol>

</div>

On the webpage, it displays as:

1. item1
2. item2 
   1. item 2.1 --- want to display as 2.1
   2. item 2.2 --- want to display as 2.2
      a. item a
      b. item b
      c. item c
   3. item 2.3 --- want to display as 2.3
3. item 3

Answer №1

Your code appears to be working correctly. When I viewed it in my browser, it displayed as you intended. If you wish to exclude the a/b/c items from the numbering, you can provide more specific instructions:

CSS:

ol {
  counter-reset: section;
  list-style-type: none;
}
#contentar>ol>li::before,
#contentar>ol>li>ol>li::before{
  counter-increment: section;
  content: counters(section,".") " ";
}

HTML:

<div id="contentar">
  <ol>
    <li> item1</li>
    <li> item2
    <ol>
      <li>item 2.1</li>
      <li>item 2.2
      <ol>
         <li>item a</li>
         <li>item b</li>
         <li>item c </li>
      </ol>
      </li>
    <li>item 2.3</li>
    </ol>
    </li>
    <li>item 3</li>
  </ol>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Activate animation while scrolling the page

I am using a progress bar with Bootstrap and HTML. Below is the code snippet: $(".progress-bar").each(function () { var progressBar = $(this); progressBar.animate({ width: progressBar.data('width') + '%' }, 1500); }); <body> & ...

Is there a way to prevent the row background color from stretching along with the content of the dropdown accordion?

Is there a way to prevent the row background color from expanding along with the content of the dropdown accordion? I want the row to remain fixed in place and have the dropdown content start below the selected row. Currently, the style of the row changes ...

Enhancing User Experience in Bootstrap 4: Making Dropdown Parents Clickable Links

<nav class="navbar navbar-expand-lg navbar-light bg-light"> <a class="navbar-brand" href="#">Navbar</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbar ...

Setting a static width for a specific cell in HTML5 - What's the best way to go about it?

When working with HTML5, how do I define a specific width for a table cell? Many of the <col> properties that were present in HTML4 are no longer applicable in HTML5. Just to clarify, I am aware that I can use <td style="width:150px">, but thi ...

Unexpected Type Error: Unable to Assign 'Render' Property to Undefined

At the moment, I am encountering these specific issues: An Uncaught TypeError: Cannot set property 'render' of undefined The element #main cannot be found This is the code that I currently have. Despite looking for solutions from various sourc ...

Positioning MDL cards in HTML documents

Seeking guidance on positioning MDL cards alongside existing text. I've attempted various methods without success so far, and the desired outcome has not been achieved. The goal is to have text aligned to the left (which is currently satisfactory) wi ...

Tips for making a div with a single triangular side using Reactjs

Hey there, I'm looking to design a header similar to the one shown in this image. Can someone provide guidance on how I can achieve this UI using React.js? https://i.sstatic.net/zmW5x.jpg ...

Form alignment issue: Bootstrap justify-content feature not functioning as expected

I am having trouble aligning my input form that is designed to capture Twitter handles in the center of the page. Despite using Bootstrap and ASP.NET, I cannot seem to get it to work as intended. Here is a snippet of the relevant CSS/HTML code: <form ...

Executing a function with a click, then undoing it with a second click

My goal is to trigger an animation that involves text sliding off the screen only when the burger icon is clicked, rather than loading immediately upon refreshing the page. The desired behavior includes activating the function on the initial click and then ...

Troubleshooting the Full Height Feature for Sidebar (Panel) in Twitter Bootstrap

I'm having issues with the Sidebar (Panel) in Twitter Bootstrap. I'm encountering some trouble with how it is displayed. Below is the CSS code I am using for the sidebar: .sharecartside .content { height: 100% !important; min-height: 10 ...

I am currently attempting to find a color picker element within a parent class using Cypress CSS Locator. While I am able to reach the parent element, I am unsure of the correct method to target the

My user interface has a list of elements displayed in 2 columns. The first column shows the name of the item, such as Manager, Operator, and the list is expected to grow. The second column consists of a color picker element where you can choose a color. I ...

Ensuring the height of the HTML element for menu items matches the navigation bar

I've been struggling to customize a navigation bar styled with Bootstrap 4. My goal is to create a hover effect on the menu items similar to the image or code snippet provided, but without that annoying thin blue flashing offset below the item. Despit ...

Transmit data from list items in the HTML to a form

Based on my understanding, there are limited options available to style an <option> tag within a <select> dropdown and it appears quite plain. So I was thinking about creating a more visually appealing dropdown using <ul> <li> tags ...

Press the add button and then click on removeclass

My table structure is as follows: <table> <tr> <td>table 1 a <span class="icon"></span></td> </tr> <tr> <td>table 2 b <span class="icon"></span></td> & ...

Dropdown button split aligned with its first button

Comparing the alignment of split button dropdowns in Bootstrap 3 and Bootstrap 4, I find that Bootstrap 3 aligns them to the left of the first button, while Bootstrap 4 only aligns them according to the second button. https://i.stack.imgur.com/gAt78.png h ...

Ways to prevent a background image from repeating in an HTML email without relying on CSS

I created a custom background picture, but when I tried to use it with CSS in Outlook, it didn't work. So, I added the picture directly into the body tag which allowed me to display it, but now it is repeating. Even after trying to prevent the repeti ...

Seeking guidance on resolving issues with this div table

After almost getting everything set up, I encountered some strange issues that have been difficult to resolve. The challenges I'm facing include: The spacing on the right side is too large. Tables always appear stacked without any spacing in bet ...

Create objects in the gallery

I recently developed a React Material-UI component using Typescript: <Grid container direction="row" justifyContent="flex-start" alignItems="flex-start"> <Grid item xs={5}> <B ...

Keep the link underlined until a different button is pressed

I need help with a webpage that displays a list of partners organized by categories. When clicking on sidebar categories, the link remains underlined. However, if you click anywhere else on the page, the link becomes inactive. CSS: button:hover { t ...

Error with adaptable menu

I am attempting to develop a responsive menu similar to the Bootstrap nav bar using only CSS. I have managed to get the functionality working, but the positioning of the menu grabber is incorrect and I'm unsure how to correct it. The grabber should al ...