CSS 新选择器

55 阅读1分钟
<!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>
        body{
            font-size: 30px;
        }   
        // 伪类选择器
        /* ul li:first-child {
            color: red;
        }
        ul li:last-child {
            color: green;
        } */
        /* ul li:nth-child(2) {
            color: blueviolet;
        } */
        ul li:nth-child(2n) {
            color: blueviolet;
        }
        // (:)伪类+(::)伪元素选择器
        ul li:nth-child(2n)::before {
            content: "";
            width: 300px;
		    height: 140px;
            display: inline-block;
            background-image: url(./跑车.png);
            background-size: cover;
            z-index: 100;
            margin-right: 20px;
        }
        ul li:nth-child(2n-1) {
            color: green;
        }
        ul li:nth-child(2n-1)::after {
            content: '9';
            color: red;
        }
        // 属性选择器
        input[type=text] {
            border: 2px solid red;
        }
        input[type=password] {
            border: 2px solid green;
        }
    </style>
</head>
<body>
    <input type="text">
    <input type="password">
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ul>
</body>
</html>