Discover an improved method for creating a custom list style using Unicode Numbers in CSS

I am interested in creating a unique list type using Khmer Unicode Numbers ១ ២ ៣.. in a precise order. To achieve this, I attempted to utilize CSS pseudo-classes

li:nth-child(1) li:nth-child(2) li:nth-child(3)..
defined in my stylesheet as follows:

ul.mainList {
  list-style-type: none;
}
ul.mainList > li {
  text-indent: -5px;
}
ul.mainList > li:nth-child(1):before {
  content: "១. ";
  text-indent: -5px;
}
ul.mainList > li:nth-child(2):before {
  content: "២. ";
  text-indent: -5px;
}
ul.mainList > li:nth-child(3):before {
  content: "៣. ";
  text-indent: -5px;
}
ul.mainList > li:nth-child(4):before {
  content: "៤. ";
  text-indent: -5px;
}
ul.mainList > li:nth-child(5):before {
  content: "៥. ";
  text-indent: -5px;
}
ul.mainList > li:nth-child(6):before {
  content: "៦. ";
  text-indent: -5px;
}
ul.mainList > li:nth-child(7):before {
  content: "៧. ";
  text-indent: -5px;
}
ul.mainList > li:nth-child(8):before {
  content: "៨. ";
  text-indent: -5px;
}

The HTML markup for the list is as follows:

<p>List of items</p>
<ul class="mainList">
    <li>Item ១</li>
    <li>Item ២</li>
    <li>Item ៣</li>
    <li>Item ៤</li>
    <li>Item ៥</li>
    <li>Item ៶</li>
    <li>Item ៷</li>
    <li>Item ៸</li>
</ul>

While this method works well, it becomes cumbersome when dealing with more than ten or twenty list items, requiring multiple declarations of li:nth-child(n). Is there a more efficient approach? Thank you.

Answer №1

Did you know that the list-style CSS attribute has a hidden gem of accepting various values, including khmer? Yes, it's true! The simplest way to implement this is by defining the list-style for your ordered list with the following code snippet:

ol.khmer {
  list-style: khmer;
}
<p>List of items</p>
<ol class="khmer">
  <li>Item ១</li>
  <li>Item ២</li>
  <li>Item ៣</li>
  <li>Item ៤</li>
  <li>Item ៥</li>
  <li>Item ៦</li>
  <li>Item ៧</li>
  <li>Item ៨</li>
</ol>

It's important to mention that not all browsers support this feature, as pointed out by @Mr_Lister. Alternatively, you can explore using @counter-style, although its support is limited. If cross-browser compatibility is crucial, sticking to a different solution might be necessary.

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

How to locate a particular element containing specific text using xpath

I have a unique set of spans to work with: <span> <span>foobar</span> <span>textexampleone</span> </span> Currently, I am attempting to utilize xpath in order to locate the span containing "textexampleone" with ...

Is there a way for me to scroll and bring the block up to the header when the button is clicked?

My goal is to create a functionality where clicking on the button with the class .booking__button will smoothly scroll the block up under the header. The position of the block should remain consistent, only the scrolling effect should be visible to the use ...

Capture the onclick attribute with jQuery and then reapply it

I am facing a challenge with a page that has several calendars composed of HTML tables where each day is represented by a td. The td elements have an onClick attribute which I need to manipulate using jQuery. Specifically, I need to remove the onClick attr ...

Customize dynamically loaded data via AJAX

I have a webpage that is loading a table from another source. The CSS is working fine, but I am facing an issue editing the table using jQuery when it's loaded dynamically through a script. It seems like my changes are not getting applied because they ...

Create a typing effect in Javascript that mimics the user's input

Trying to simulate a typing effect with the sentence extracted from user input using JavaScript, but encountering some issues. Successfully capturing and displaying the input in the console with console.log(), however, incorporating the typing effect func ...

Adjust the size of an iFrame's content according to the dimensions of the iFrame

I am looking to use an iFrame for embedding a map, and my goal is to resize the map according to the values in the iFrame tag. Most tutorials I have found focus on auto-sizing the iFrame based on content, which is not what I need. Just to make it clear, I ...

Can we set $_SESSION equal to $_POST data?

I'm not sure if I'm on the right track, but let's consider this scenario. form.php <?php session_start(); $_SESSION['average'] = $num; echo ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <h ...

The dimensions of the box remain fixed and do not change when the screen is resized

Just starting out with HTML and CSS and trying to create a responsive website. Running into an issue where the black striped box on my page is not moving up when I resize the screen. It appears to be stuck in place, causing a gap between it and the slide s ...

Looking to transform a nested JSON structure into a visually appealing HTML table with merged rows?

My JSON structure appears as follows: $scope.data = [ { "type":"Internal", "count": 3, "library" : [ { "type":"Library 123", "count": 2, "version" ...

The image fails to display when using THREE.js and Panolens.js

Trying to create a 360-degree environment with informational buttons using THREE.js and Panolens.JS However, I'm unable to resolve why the image is not appearing. Continuously encountering the error: Uncaught ReferenceError: process is not defined. ...

The customized Vaadin component with a tag is missing from the MainView layout

I am attempting to integrate my custom vis component into the MainView VerticalLayout. However, it is appearing above the layout and the layout itself contains an empty component tag. Custom component code In this section, I have labeled my component as " ...

Designing a photo frame slider for a unique touch

My skills in javascript and jQuery are limited, but I am looking to create a customizable slider. While exploring options like Flexslider (), I found it challenging to meet the following specifications: Eliminate color gaps between thumbnails Enable thu ...

Setting the position of a tooltip relative to an element using CSS/JS

I'm struggling to make something work and would appreciate your help. I have a nested list of items that includes simple hrefs as well as links that should trigger a copy-to-clipboard function and display a success message in a span element afterwards ...

Display the source code of an HTML element when clicked

Is there a way to show the source code of an element on a webpage in a text box when that specific element is clicked? I am wondering if it is feasible to retrieve the source code of an element upon clicking (utilizing the onClick property), and subseque ...

failure of svg spinning

I'm currently working with an SVG file and attempting to incorporate a spinning animation similar to loaders and spinners. However, I am facing an issue where the rotating radius is too large and I am struggling to control it effectively. CSS: .image ...

My website is being cut off

After creating this website with a viewport setup, I noticed that it is not fully visible on certain screens. When viewed on a CRT monitor at 800x600 desktop resolution or lower than 1280x800, such as on mobile devices, the content gets clipped. Is there a ...

Creating an interactive map using Python with Folium, incorporating a draggable legend and clickable items for users to easily zoom into specific locations

Looking to create an interactive map with python folium package. Need icons for locations and a draggable legend that allows for repositioning by mouse drag. Also need ability to click on legend items to zoom into corresponding locations on the map. Can s ...

javascript Why isn't the initial click registering?

In my table, users can select certain rows by using checkboxes. I have implemented some JavaScript functionality that allows them to select each checkbox individually and also use a "Select All" option. Additionally, there is code written to enable the use ...

Leveraging jQuery selectors to manipulate data received from an Ajax response

I am encountering an issue with an Ajax call and response. Previously, I had a block of regular javascript code that successfully transformed my select element into a select2 widget. However, when I attempt to convert the select element into a select2 usi ...

Is there a way to align two links side by side, with one on the left and the other on the right?

<a href="example"><p style="text-align:left">Previous Page</a> <a href="example"><p style="text-align:right">Next Page</a> I am trying to figure out how to align these links on the same line. Any suggestions would be a ...