Structural pseudo-class selector

Goal: To be able to locate elements in HTML using structural pseudo-class selectors
insert image description here
insert image description here

The 4th and 8th commonly used in web pages, we found that they are all multiples of 4, then use 4n to select them.
insert image description here

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* ** 偶数 */
        /* li:nth-child(2n) { */

            /* *** 奇数 */
        /* li:nth-child(2n+1) { */
            /* 找到前3个 */
        /* li:nth-child(-n+3) { */

            /* *** 4的倍数 */
        li:nth-child(4n) {
    
    
            background-color: green;
        }
    </style>
</head>
<body>
    <ul>
        <li>这是第1个li</li>
        <li>这是第2个li</li>
        <li>这是第3个li</li>
        <li>这是第4个li</li>
        <li>这是第5个li</li>
        <li>这是第6个li</li>
        <li>这是第7个li</li>
        <li>这是第8个li</li>
    </ul>
</body>
</html>

Guess you like

Origin blog.csdn.net/qq_42931285/article/details/123950216