css selector

original address

Selector: which tag to operate on

basic selector

Tag selector

Use the tag name as the name of the selector.

This example sets different font and background colors for different labels.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>css基本选择器一</title>
        <style type="text/css" >
            div{
                background-color: yellow;
                color: blue;
            }
            
            p{
                background-color: red;
                color: gray;
            }
        </style>
    </head>
    <body>
        <div>hjwblog.com</div>
        <p>hjwblog.com</p>
    </body>
</html>

class selector

Each html tag has a class attribute

You can use 标签名.类名{}the format setting for the specified class in the specified tag

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>css基本选择器二</title>
        <style type="text/css" >
            div.hjw{
                background-color: black;
                color: red;
            }
        </style>
    </head>
    <body>
        <div class="hjw">hjwblog.com</div>
    </body>
</html>

This can be done by .类名{}specifying the format of different tags with the same class name.

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>css基本选择器二</title>
        <style type="text/css" >
            .hjw{
                background-color: black;
                color: red;
            }
        </style>
    </head>
    <body>
        <div class="hjw">hjwblog.com</div>
        <p class="hjw">hjwblog.com</p>
    </body>
</html>

id selector

Each html tag has an attribute on itid

Use 标签名#id{}to format the content of the specified id under the specified tag

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title>css基本选择器三</title>
        <style type="text/css" >
            div#hjw{
                background-color: yellow;
                color: red;
            }
        </style>
    </head>
    <body>
        <div id="hjw">hjwblog.com</div>
    </body>
</html>

Use #id名{}to format all labels with the specified id.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325062962&siteId=291194637