类名选择器与id选择器

这是类名选择器的介绍

下面是一个简单的类名选择器,代码如下:

<!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>多类名选择器</title>
    <style>
        .pink {
            color: pink;
            background-color: bisque;
        }

        .pal {
            color: palevioletred;
        }

        .white {
            color: white;
        }

        .box {
            width: 520px;
            height: 200px;
            font-size: 60px;
        }
    </style>
</head>

<body>
    <!-- <div style="">你干嘛</div>
    <div style="哎呦</div>
    <div style="鸡哥</div>-->
    <div class="pink box">木更老婆</div>
    <div style="background-color: black;" class="pal box">神子老婆</div>
    <div style="background-color: purple;" class="white box">影宝</div>
</body>

</html>
代码运行效果如下:

多类名选择器在开发中的使用场景是这样的

id选择器的介绍如下

 
id选择器的代码如下:

<!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>
        #pink {
            color: pink;
            background-color: bisque;
            font-size: 60px;
            width: 520px;
            height: 200px;
        }

        #skyblue {
            color: skyblue;
            background-color: azure;
            font-size: 60px;
            width: 520px;
            height: 200px;
        }

        #red {
            color: red;
            background-color: beige;
            font-size: 60px;
            width: 520px;
            height: 200px;
        }
    </style>
</head>

<body>
    <div id="pink">木更老婆</div>
    <div id="skyblue">绫华老婆</div>
    <div id="red">胡桃老婆</div>
</body>

</html>
代码运行效果如下:
 
这是基础选择器的介绍,有它们的作用,特点和使用情况
posted @ 2023-01-05 16:01    阅读(61)  评论(0)    收藏  举报