Home Web Front-end CSS Tutorial Serialized directory listing

Serialized directory listing

Mar 21, 2018 pm 04:25 PM
list Table of contents

This time I will bring you a directory list with a serial number, and implement a directory list with a serial number. Notes What are the following? Let’s take a look at the actual case.

When writing a document manual, we often need the serial number in front of the list item and the serial number of the superior layer in front, as shown below:

(Figure 1)

But in the default

    list, any level starts with a single serial number. As shown below:

    (Picture 2)

    To achieve the effect of Figure 1, one of the methods is to directly use the serial number part as part of the list content and insert the corresponding HTML, you can use js to insert serial numbers in batches.

    The generated HTML result is similar to this

    <ol>  
      <li>1. 列表项  
        <ol>  
          <li>1.1. 列表项  
            <ol>  
              <li>1.1.1 列表项</li>  
              <li>1.1.2 列表项</li>  
              <li>1.1.3 列表项</li>  
            </ol>  
          </li>  
        </ol>  
      </li>  
    </ol>
    Copy after login


    If you neither want to hard-write the serial number in the html code nor introduce js, you can only use HTML attributes## Breakthroughs were made in both # and CSS.

    Unfortunately,

    HTML element attributes do not provide a similar interface.

    After a tip from a netizen, I learned that there is a concept called css counter, but I am ignorant.

    After querying the relevant documents, the CSS solution will be available.

    HTML code is as follows:

    <ol>  
      <li>列表项  
        <ol>  
          <li>列表项  
            <ol>  
              <li>列表项</li>  
              <li>列表项</li>  
              <li>列表项</li>  
            </ol>  
          </li>  
        </ol>  
      </li>  
    </ol>
    Copy after login
    CSS code is as follows:

    ol {padding:0 0 0 20px;margin:0;list-style:none;}  
    li:before {color:#f00; font-family:Times New Roman;}  
    li{counter-increment:a 1;}  
    li:before{content:counter(a)". ";}  
    li li{counter-increment:b 1;}  
    li li:before{content:counter(a)"."counter(b)". ";}  
    li li li{counter-increment:c 1;}  
    li li li:before{content:counter(a)"."counter(b)"."counter(c)". ";}
    Copy after login
    The effect is Figure 1 at the beginning of this article.

    But this CSS is really ugly. There are several levels of directories, so you have to write several layers of CSS. Obviously it shouldn't be like this.

    After continuing to read the relevant documents and clarifying counter-reset, counter(), counters(), I found that the problem was extremely simple.

    The CSS code is as follows:

    ol {padding:0 0 0 20px;margin:0;list-style:none;counter-reset:a;}  
    li:before {counter-increment:a;content:counters(a,".")". ";}
    Copy after login
    In this way, no matter how many levels of nested lists there are, the cascading sequence numbers can be displayed correctly, and the effect is as shown in Figure 1 at the beginning of this article.

    It should be pointed out that: before, counter-increment and other related CSS features do not support the ancient IE6/IE7, but IE8 and above are well supported.

    I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

    Recommended reading:

    What is the difference between href and src, link and @import

    How is the absolute positioning of css compatible? All resolutions

    CSS3 properties transition, animation, transform

    The above is the detailed content of Serialized directory listing. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to remove square brackets from a list using Python How to remove square brackets from a list using Python Sep 05, 2023 pm 07:05 PM

Python is a very useful software that can be used for many different purposes depending on the need. Python can be used in web development, data science, machine learning, and many other fields that require automation. It has many different features that help us perform these tasks. Python lists are one of the very useful features of Python. As the name suggests, a list contains all the data you wish to store. It is basically a set of different types of information. Different Ways to Remove Square Brackets Many times, users come across a situation where list items are displayed within square brackets. In this article, we'll detail how to remove these brackets to get a better view of your listing. One of the easiest ways to remove parentheses in strings and replacement functions is in

How to count the number of elements in a list using Python's count() function How to count the number of elements in a list using Python's count() function Nov 18, 2023 pm 02:53 PM

How to use Python's count() function to calculate the number of an element in a list requires specific code examples. As a powerful and easy-to-learn programming language, Python provides many built-in functions to handle different data structures. One of them is the count() function, which can be used to count the number of elements in a list. In this article, we will explain how to use the count() function in detail and provide specific code examples. The count() function is a built-in function of Python, used to calculate a certain

How to Make a Shopping List in the iOS 17 Reminders App on iPhone How to Make a Shopping List in the iOS 17 Reminders App on iPhone Sep 21, 2023 pm 06:41 PM

How to Make a GroceryList on iPhone in iOS17 Creating a GroceryList in the Reminders app is very simple. You just add a list and populate it with your items. The app automatically sorts your items into categories, and you can even work with your partner or flat partner to make a list of what you need to buy from the store. Here are the full steps to do this: Step 1: Turn on iCloud Reminders As strange as it sounds, Apple says you need to enable reminders from iCloud to create a GroceryList on iOS17. Here are the steps for it: Go to the Settings app on your iPhone and tap [your name]. Next, select i

How to create a grocery list: Use the Reminders app for iPhone How to create a grocery list: Use the Reminders app for iPhone Dec 01, 2023 pm 03:37 PM

In iOS 17, Apple added a handy little list feature to the Reminders app to help you when you're out shopping for groceries. Read on to learn how to use it and shorten your trip to the store. When you create a list using the new "Grocery" list type (named "Shopping" outside the US), you can enter a variety of food and groceries and have them automatically organized by category. This organization makes it easier to find what you need at the grocery store or while out shopping. Category types available in alerts include Produce, Bread & Cereals, Frozen Foods, Snacks & Candy, Meat, Dairy, Eggs & Cheese, Baked Goods, Baked Goods, Household Products, Personal Care & Wellness, and Wine, Beer & Spirits . The following is created in iOS17

The glob() function in PHP is used to find files or directories The glob() function in PHP is used to find files or directories Nov 18, 2023 pm 06:17 PM

The glob() function in PHP is used to find files or directories and is a powerful file operation function. It can return the path of a file or directory based on a specified pattern match. The syntax of the glob() function is as follows: glob(pattern, flags) where pattern represents the pattern string to be matched, which can be a wildcard expression, such as *.txt (matching files ending with .txt), or a specific file path. flags is an optional parameter used to control the function

What is the difference between Del and remove() on lists in Python? What is the difference between Del and remove() on lists in Python? Sep 12, 2023 pm 04:25 PM

Before discussing the differences, let us first understand what Del and Remove() are in Python lists. Del Keyword in Python List The del keyword in Python is used to delete one or more elements from a List. We can also delete all elements, i.e. delete the entire list. Example of using del keyword to delete elements from a Python list #CreateaListmyList=["Toyota","Benz","Audi","Bentley"]print("List="

Create multiple directories from a list using Python Create multiple directories from a list using Python Sep 08, 2023 am 08:21 AM

Python has become one of the most popular programming languages ​​for various applications due to its simplicity and versatility. Whether you are an experienced developer or just starting out on your coding journey, Python offers a wide range of features and libraries that make complex tasks manageable. In this article, we will explore a practical scenario where Python can help us by automating the process of creating multiple directories based on a list. By leveraging the power of Python's built-in modules and techniques, we can handle this task efficiently without the need for manual intervention. In this tutorial, we will delve into the problem of creating multiple directories and provide you with different ways to solve this problem using Python. By the end of this article, our goal is for you

How to automatically generate a directory. How to set the format of the automatically generated directory. How to automatically generate a directory. How to set the format of the automatically generated directory. Feb 22, 2024 pm 03:30 PM

Select the style of the catalog in Word, and it will be automatically generated after the operation is completed. Analysis 1. Go to Word on your computer and click to import. 2After entering, click on the file directory. 3 Then select the style of the directory. 4. After the operation is completed, you can see that the file directory is automatically generated. Supplement: The table of contents of the summary/notes article is automatically generated, including first-level headings, second-level headings and third-level headings, usually no more than third-level headings.

See all articles