home page Site building tutorial web front end text

Pure css realizes automatic addition of serial number to the list

When we write style codes, we occasionally use the design of digital ranking lists, which are listed by serial number. For example, the popular/popular ranking in the beautiful mipCms theme: if the li element is used in conjunction with the list style: decimal; Attribute, there will be an English full stop followed by the number, which cannot meet the effect we want; If a separate element is added to place serial numbers or images, it is a bit of a fuss and increases the amount of page code. At this time, we can try to use pseudo elements in combination with counter incre

We write style The digital ranking list is occasionally used in the code Design , ranking by serial number, for example: beautiful mipCms theme Top/hot reviews in:

 Pure css realizes automatic addition of serial number to the list css sorting css serial number figure 1

If the li element is used with list style: decimal; Attribute, there will be an English full stop followed by the number, which cannot meet the effect we want; If a separate element is added to place serial numbers or images, it is a bit of a fuss and increases the amount of page code.

At this time, we can try to use pseudo elements combined with the counter amendment attribute to simply achieve the effect we want. The specific code is as follows:

html code

 <ul> <li>Beautiful corporate brand marketing theme</li> <li>Beautiful Online Consultation feedback plug-in </li> <li>Exhibition theme of beautiful Chinese style products</li> <li>Beautiful and free version enterprise station Responsive Theme</li> <li>Beautiful and luxurious version response Style Theme</li> </ul>

Css style

 ul {     margin: 0;     padding: 0;     counter-reset: li; } ul > li:before {     content: counter(li);     counter-increment: li; }

As for the top three different backgrounds colour It can be realized by combining nth child selector

 ul > li:nth-child(1):before,ul > li:nth-child(2):before,ul > li:nth-child(3):before{color: #fff;} ul > li:nth-child(1):before {     background: #FF6B57; } ul > li:nth-child(2):before {     background: #2ea7e0; } ul > li:nth-child(3):before {     background: #6bc30d; }
Reward
poster

Statement: Some of the resources on this site are original works on the site, and some are publicly shared and collated based on the Internet. The copyright belongs to the original author.
If it infringes your rights, please contact our website, and we will deal with it as soon as possible. Thank you. Please indicate the source of the transfer

Link to this article: https://www.umtheme.com/web/189.html

Related recommendations

 CSS cardioid winding rotation effect

CSS cardioid winding rotation effect

CSS heart-shaped winding and rotating effect is an interesting animation effect, which can bring romantic and dynamic atmosphere to web pages. This effect will rotate a heart-shaped pattern infinitely, and twist around a central point at the same time
web front end 2023.09.13 zero two thousand two hundred and twenty-five
 Create css3 animation effects commonly used in h5

Create css3 animation effects commonly used in h5

Css3 provides many powerful special effects that can be used to achieve a variety of effects. Here are some common css3 effects that I summarize, which can be directly referenced if necessary: 1. Zoom in when levitating:. one {transition: All 0.4s&nb
web front end 2023.09.13 zero two thousand and five
Post comments

Thank you for your support